Re: Regex..can i do this?
How about a little function to format the part nunmber? Something like this:
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim test() As String = {"1245", "1245-2A", "C1125-12CB", "V11259"}
Dim display As String = ""
For Each str As String In test
display &= FormatPartNumber(str, "x"c, ) & vbCrLf
Next
MsgBox(display)
End Sub
Public Function FormatPartNumber(ByVal partNum As String, _
Optional ByVal paddingChar1 As Char = " "c, _
Optional ByVal paddingChar2 As Char = "0"c) _
As String
Dim retString As String = ""
Dim prefix As String = ""
Dim number As String = ""
Dim suffix As String = ""
Dim strTemp As String() = partNum.Split("-"c)
If strTemp.Length > 1 Then
suffix = "-" & strTemp(1)
End If
Dim chrArray As Char() = strTemp(0).ToCharArray
For Each ch As Char In chrArray
If Char.IsLetter(ch) Then
prefix &= ch.ToString()
Else
number &= ch.ToString()
End If
Next
retString = prefix.PadLeft(3, paddingChar1) & _
number.PadLeft(6, paddingChar2) & _
suffix
Return retString
End Function
Re: Regex..can i do this?
Probably be easier to do it with string manipulation than with regex, like the above post had mentioned.
Re: Regex..can i do this?
Quote:
Originally Posted by gigemboy
Probably be easier to do it with string manipulation than with regex, like the above post had mentioned.
StanAV code works great. I'd like see it done with Regex to.? I did a goolge search on RegEx and downloaded some editpro pad..or something like that to do the tutorials. I had to restore my computer because I think it installed some virus or something. My machine got real pokie after I installed it. Hopefully the restore will work. I want home after I started the restore so I wont know till monday. Anyway, if anyone is good with regex expressions I would like to see it done that way.
Thanks, Dave
Re: Regex..can i do this?
Well regular expressions are really made to "find" text that matches a pattern. I could see it being used to find the actual part numbers in some sort of text, but you already have the part numbers. It would probably require several expressions, I believe, one in order to match on the text inside of the part number you want, and then a regex replace (or regular string replace) statement to replace it with the text you want.
I have used Regex several times, and when you want to start replacing text that you are matching on, it gets a little tricky. Its not as easy as it sounds and I don't really know how to do it without writing out several different statements.