Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm just wondering if there is a .NET method for doing this tedious task ... I have data set (obtained from swiping a magnetic card) that is stored in a single string ...

 

The data is separated sometimes by actual field length, and in some instances by separators. I am using code like this to parse the data and was wondering if there was a better .NET method for handling strings in this manner ...

 

TIA!

M.

 

       ' Card Number
       m_strCardNumber = Mid$(strSwipeData, 9, 10)

       ' First, Middle, Last from "^Last/First Middle^"
       ' Last ends at a '/', First and Middle separated by Space
       ' enclosed in '^' (carots)
       For iLoop = 1 To Len(strSwipeData)
           Select Case Mid$(strSwipeData, iLoop, 1)
               Case "^"
                   If intNameLOC_Begin = 0 Then
                       intNameLOC_Begin = iLoop + 1
                   Else
                       intNameLOC_End = iLoop + 1
                       Exit For
                   End If
               Case "/"
                   intNameLOC_FirstName = iLoop + 1
               Case " "
                   intNameLOC_MiddleName = iLoop + 1
           End Select
       Next iLoop
       m_strName_Last = Mid$(strSwipeData, intNameLOC_Begin, intNameLOC_FirstName - intNameLOC_Begin - 1)
       m_strName_First = Mid$(strSwipeData, intNameLOC_FirstName, intNameLOC_MiddleName - intNameLOC_FirstName - 1)
       m_strName_Middle = Mid$(strSwipeData, intNameLOC_MiddleName, intNameLOC_End - intNameLOC_MiddleName - 1)


  • *Experts*
Posted

Check out the tutorial on regular expression matching. You can define a regular expression that matches your string and use the Matches object to get each piece handed to you (First, Middle and Last).

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

Take a look at this thread

 

-nerseus

 

PS Don't forget to use the help files that ship with Visual Studio - they have a ton of help and samples and give you the specifics of each object.

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • Moderators
Posted

The first thing I thought of using was regular expressions, but a real simple a fast approach would be to use the Split function...

       strSwipeData = "^Smith/John myMid^"

       strSwipeData = strSwipeData.Replace("^", "")

       Dim temp() As String
       Dim temp2() As String

       temp = strSwipeData.Split("/"c)
       temp2 = temp(1).Split(" "c)

       m_strName_Last = temp(0)
       m_strName_First = temp2(0)
       m_strName_Middle = temp2(1)

Visit...Bassic Software
Posted

I like the regular expression approach .. there are a total of 17 fields that are stored in this magnet swipe string ... I'm guessing I have to write one regular expression that matches the format of the string, but then how do I use the match function to seek the data in the string? The match function searches for data matches (if I use that example Nerseus posted earlier) it looks for "S" ... not everything has a separator .. some information (at the beginning and end) is size delimited (ie. fixed length fields) ... Can this be parsed using RegEx?

 

M.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...