CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2002
    Location
    United Kingdom
    Posts
    60

    2 string manipulation questions....

    Hi,

    Question 1:

    OK, I have a string called MyString as follows:

    MyString = "[Letters]ABCDE[Numbers]1234"

    I want to click a button and for it to search the string for [Letters] then display in 'MyStringNew' just the letters (ABC, etc), i.e. not the numbers section.

    Question 2:

    In the above string, how can I also show everything after [Letters] to the end of the string.

    Thanks!!

    Mark

  2. #2
    Join Date
    Aug 2000
    Location
    Essex, Uk
    Posts
    1,214
    Ans to Q2

    newVal = Right(mystring, Len(mystring) - (InStr(1, mystring, "]")))

    Before Answering Q1,

    Will the string always be in the format you have shown?
    If you find my answers helpful, dont forget to rate me

  3. #3
    Join Date
    Aug 2000
    Location
    Essex, Uk
    Posts
    1,214
    Mark assuming it's in this fomat, then you retrieve the letters part with the following

    letters = left(right(mystring,len(mystring) - instr(1,mystring,"]")),instr(1,right(mystring,len(mystring) - instr(1,mystring,"]")),"[")-1)

    and for the numbers:

    numbers = Right(mystring, Len(mystring) - InStr(10, mystring, "]"))
    If you find my answers helpful, dont forget to rate me

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