473,508 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

check if string contain substring

Hi!

I would like to check if string contain specific substring.

How to do it?

P.S. I've done something stupid like

String.Replace

If str1<>str2....

Nov 15 '05 #1
3 45081
Ivan,

In the .net help index, lookup the string class, and then look at all the
methods available. For instance, the IndexOf method might do the trick.

String strMyString = "Neat";
Int32 iLocation = strMyString.IndexOf("a");

if ( iLocation >= 0 )
{
//Do something
}

Mark

"Ivan Demkovitch" <i@a.b> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi!

I would like to check if string contain specific substring.

How to do it?

P.S. I've done something stupid like

String.Replace

If str1<>str2....

Nov 15 '05 #2
I would do something like this:

if (str.IndexOf(str2) == -1) ...

IndexOf returns -1 it cannot find str2 in str1

Dave
Hi!

I would like to check if string contain specific substring.

How to do it?

P.S. I've done something stupid like

String.Replace

If str1<>str2....


--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #3
Thank you guys!

Thats indeed nicer way of doing it.

I looked thru sring class like 5 times and didn't stop on IndexOf() :-)

"Ivan Demkovitch" <i@a.b> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi!

I would like to check if string contain specific substring.

How to do it?

P.S. I've done something stupid like

String.Replace

If str1<>str2....

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
12561
by: Cyrus D. | last post by:
Hi guys, I want to validate a string to make sure it contains only digits. 0001 = true 6669 = true 00a0 = false 6.665 = false What's the best way to go about doing that ?
1
3889
by: Xah Lee | last post by:
# strings can be joined by +. print "this" + " that" # string can be multiplied print "this" *5 # substring extraction is done by appending a bracket # with begin and ending index a="this...
15
6765
by: zealotcat | last post by:
Hi, all: I want to implement a function (using std::string and std::vector) split a string contain special token into vector. eg: string = "alex delia john" ==> vector = "alex"; vector =...
6
9250
by: kellygreer1 | last post by:
What is a good one line method for doing a "length safe" String.Substring? The VB classes offer up the old Left function so that string s = Microsoft.VisualBasic.Left("kelly",200) // s will =...
4
5360
by: Jason | last post by:
I have a string that looks like this? ihelloworld_zzz_yyy In a single vb.net line, I want to remove the frist character and anything after and including the first "_" resulting in : ...
8
19737
by: varsha.gadekar | last post by:
what is the easy way to check if the given string is substring of other string only using c++?
7
15275
by: bcpkh | last post by:
Hello All I need to check a string to make sure it does not contain any non numeric characters, the problem that I face is that the string is fairly long, 2784601121574585949, strtol etc. can't...
2
10893
by: Ken | last post by:
Is there a way if a string contain upper cas letter? Is there a way if a string contain Numbers? Is there a way if a string contain (Puntuation/Symbols) such as ~,!,#,$....? Thanks
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.