Results 1 to 9 of 9

Thread: Extracting text from a string.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Posts
    89

    Exclamation Extracting text from a string.

    I was finally able to find an API to copy all text from a terminal emulator (legally provided by the software company).


    There is a USA Social Security number I would like to extract and disregard all the other text. Once the SSN is narrowed down from all the text, can we assign it to a variable?

    I thought a RegEx would do it but probably not. I can't hardcode a social security number (defeats the purpose). Any ideas?

    Chris

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    How about this ???
    VB Code:
    1. 'if you know SSN position within that text
    2. 'then use Mid() function to assign it to some global/local var
    3.  
    4. Dim strSSN As String
    5.  
    6. strSSN = Mid(strText, intSatr, int End)
    7.  
    8. 'you are now ready to use it

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Does the security number always start from the same position?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Posts
    89
    Hmm I wish the positioning of the SSN was the same place everytime. So let's say our string variable that copied all the application's text has alot of characters like this:



    strTheAppsString = "123 Application Name: Chris Last Name: Chang Tele: %%^$%%^ SSN: 666-66-6666"

    Sometimes it would look like this:


    strTheAppsString = "123 Application Name: SSN: 666-66-6666" Chris Last Name: Chang Tele: %%^$%%^

    Another idea would be to Extract 11 characters after we parse through and if we see "SSN:" in the string, extract 11 #'s.


    Thanks for any ideas
    Chris

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    VB Code:
    1. Dim Temp As String, Temps() As String
    2.  
    3. Temps = Split(InputString, "SSN: ")
    4. If UBound(Temps) > 0 Then Temp = Left$(Temps(1), 11)
    5. ' Temp should now be either empty or contain the number

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Posts
    89
    Merri,

    Awesome code! Would you happen to know how to remove the hyphens too while we're on this subject?


    Chris

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Hyphens? The - character? (English isn't my native)

    VB Code:
    1. Temp = Replace$(Left$(Temps(1), 11), "-", vbNullString)
    2. 'vbNullString is the same as "", but it is recommended to use vbNullString

  8. #8
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    VB Code:
    1. Dim TheString As String, TheArray() As String
    2. TheString = "123 Application Name: SSN: 666-66-6666 Chris Last Name: Chang Tele: %%^$%%^"
    3. TheArray = Split(TheString, "SSN: ")
    4. MsgBox Mid(TheArray(1), 1, 11)
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Posts
    89
    Merri, Arc:

    Both samples work! Thank you for helping me out!


    Chris

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