mpappert Posted February 10, 2003 Posted February 10, 2003 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) Quote
Moderators Robby Posted February 10, 2003 Moderators Posted February 10, 2003 You can optimize this in VB6 as well as in VB.NET. Quote Visit...Bassic Software
*Experts* Nerseus Posted February 10, 2003 *Experts* Posted February 10, 2003 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 Quote "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
mpappert Posted February 10, 2003 Author Posted February 10, 2003 Ok .. I will look at regular expressions! Thanks!! M. Quote
*Experts* Nerseus Posted February 10, 2003 *Experts* Posted February 10, 2003 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. Quote "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 Robby Posted February 10, 2003 Moderators Posted February 10, 2003 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) Quote Visit...Bassic Software
mpappert Posted February 10, 2003 Author Posted February 10, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.