|
-
February 29th, 2008, 01:51 AM
#1
find substring in a string
is string provide any function that allow to calculate there is how many substring inside a string??
example: string str = "how are you?"
is it possible to tell how many "o" inside the str?
-
February 29th, 2008, 01:54 AM
#2
Re: find substring in a string
Use the substring() command with a variable. when you find the string, move the variable past it, and then LOOP until you don't find it again.
that's actually pseudo-code that will solve the problem
-
February 29th, 2008, 02:30 AM
#3
Re: find substring in a string
Another way would be to use Regular expressions.
Code:
string str = "how are you?";
System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex("o");
int i = rx.Matches(str).Count;
-
February 29th, 2008, 05:03 AM
#4
Re: find substring in a string
 Originally Posted by Shuja Ali
Another way would be to use Regular expressions.
Code:
string str = "how are you?";
System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex("o");
int i = rx.Matches(str).Count;
Excellent.
-
February 29th, 2008, 05:48 AM
#5
Re: find substring in a string
 Originally Posted by Shuja Ali
Another way would be to use Regular expressions.
Code:
string str = "how are you?";
System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex("o");
int i = rx.Matches(str).Count;
Thank you very much....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|