|
-
March 28th, 2011, 06:20 PM
#1
[RESOLVED] Get substrings from a string
Hello, suppose I have a string that has length n.
Now if m<n is given, I want to find all substrings which have a fix length m.
Is there a quick way?
Thanks for share your code.
-
March 28th, 2011, 07:28 PM
#2
Re: Get substrings from a string
Not unless there is a distinct delimiter between each sub-string
-
March 28th, 2011, 08:47 PM
#3
Re: Get substrings from a string
Code:
// set m 'n' n
int n = 20;
int m = 7;
// make a "reasonable" test string of length n
string myString = string.Empty;
for (int i = 0; i < n; i++)
myString += (i % 10).ToString();
// show all substrings of length m
for (int i = 0; i < n - m + 1; i++)
Debug.WriteLine(myString.Substring(i,m));
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
March 28th, 2011, 09:24 PM
#4
Re: Get substrings from a string
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
|