Results 1 to 9 of 9

Thread: [RESOLVED] Simple String Manipulation

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Resolved [RESOLVED] Simple String Manipulation

    I have values that change in string length.
    Say 234547,54677,7899077....
    I would like to use substring to get the last five digits from every value.
    For example the above would give me 34547,54677,99077
    How do i do it?

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Simple String Manipulation

    Use String.Split to split the string at , and then loop through the resulting array to get last 5 characters of easch string.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3
    Fanatic Member eSPiYa's Avatar
    Join Date
    Jun 2006
    Location
    in our house
    Posts
    751

    Re: Simple String Manipulation

    use Split function and "," as the delimiter then
    use loop and Right function.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Simple String Manipulation

    Sorry, i confused by including the comma there.
    Each value is on its own.

  5. #5
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Simple String Manipulation

    Quote Originally Posted by maps
    Sorry, i confused by including the comma there.
    Each value is on its own.
    Then you can just use Substring to get the last 5 characters.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Simple String Manipulation

    My problem is that substring maniplulation starts from the left to the right and unless all values have the same length, i cant manipulate to get the last 5 digits.
    A work around is what i am seeking.

  7. #7
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Simple String Manipulation

    How about using this
    VB Code:
    1. string sTemp = "7899077";
    2.             MessageBox.Show(sTemp.Substring(sTemp.Length - 5,5));
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  8. #8
    Fanatic Member eSPiYa's Avatar
    Join Date
    Jun 2006
    Location
    in our house
    Posts
    751

    Re: Simple String Manipulation

    How about this:

    VB Code:
    1. Dim myString As String = "234547,54677,7899077,345"
    2.         Dim Ctr As Integer
    3.  
    4.         For Ctr = 0 To Strings.Split(myString, ",", , CompareMethod.Text).Length - 1
    5.             MsgBox(Strings.Right(Strings.Split(myString, ",", , CompareMethod.Text)(Ctr).ToString, 5))
    6.         Next

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: Simple String Manipulation

    I am sooo Dumb Today! Thanks.

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