CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2006
    Posts
    326

    [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.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Get substrings from a string

    Not unless there is a distinct delimiter between each sub-string
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    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.......

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Get substrings from a string

    scarf

    scar
    car
    scarf
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured