﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » .NET Forums » General .NET Discussion  » How to parse alphanumeric value?</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Thu, 28 May 2026 13:59:24 GMT</lastBuildDate><ttl>20</ttl><item><title>How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27445.aspx</link><description>I have a field which may have alphanumeric values like this:&lt;br&gt;
[quote]&lt;br&gt;
AMDNY-0001253&lt;br&gt;
AMDNJ-0011253&lt;br&gt;
000001253&lt;br&gt;
XXHAM 1253&lt;br&gt;
[/quote]&lt;br&gt;
&lt;br&gt;
I need to get the numeric part to do some calculations and then assembly the alpha + numeric part again.  Is there any cool .Net function that would help me on this process instead of me looping the value backwards to get only the numeric part of 1253 in the above example?</description><pubDate>Tue, 22 Jun 2010 22:10:15 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27518.aspx</link><description>Glad to hear it! Sounds like RegexMagic is quite helpful.</description><pubDate>Tue, 22 Jun 2010 22:10:15 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27517.aspx</link><description>Hi Greg and all,&lt;br&gt;
&lt;br&gt;
Just to let you know that today I finally had the opportunity to test a Regex match and replace and with the help of the RegexMagic I was able to create the correct pattern and replaced the previous flat condition which had to match several characters using String.Replace().Replace(), etc.&lt;br&gt;
&lt;br&gt;
Once again, thanks for the contribution and push :D nicely for us to move in the right direction :P</description><pubDate>Tue, 22 Jun 2010 19:42:18 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27460.aspx</link><description>I think I'd try RegexMagic.  It looks really accessible, with the ability to build regex patterns without having to actually know regex (i.e. they've abstracted out many pattern matching concepts to a higher level...you can search for a SSN rather than having to know the regex ([0-9]{3}-[0-9]{2}-[0-9]{4}).   It also can generate code snippets for you.  And there is a free trial...  Sounds like its worth a try to me!&lt;br&gt;
&lt;br&gt;
[url]http://www.regexmagic.com/[/url]&lt;br&gt;
[url]http://www.regexmagic.com/download.html[/url]&lt;br&gt;
&lt;br&gt;
Regex Buddy is more useful if you already know regex (or want to learn it) and it doesn't have a free trial (but does have a nice money back guarantee).&lt;br&gt;
&lt;br&gt;
My guess is that you'd still want to learn regex, but regex magic might make it possible to start using regex without the hours of trying to figure out how to build a pattern, which might actually increase the speed you learn it.</description><pubDate>Wed, 16 Jun 2010 11:59:57 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27459.aspx</link><description>Whatever tool you use notice there is a regex tutorial link on the ultrapico page.&lt;br&gt;</description><pubDate>Wed, 16 Jun 2010 10:17:40 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27458.aspx</link><description>Thanks Charles,&lt;br&gt;
&lt;br&gt;
Believe me, taking a quick look at the Regex Magic and Buddy, they looks very powerful and I like the fact of how they highlight all parts to be matched.&lt;br&gt;
&lt;br&gt;
[url=http://www.ultrapico.com/Expresso.htm]Expresso[/url] looks good but I am under the impression that you need to be a more Regex experience developer to take the best of that tool.&lt;br&gt;
&lt;br&gt;
The [url=http://www.just-great-software.com/]Just-Great-Software[/url] tools feels like a more intuitive tool, even though there is no a trial or demo version, the money back policy looks good and also the price is very affordable for such a tool, now the question is which one to choose Regexbuddy or RegexMagic? :cool:</description><pubDate>Wed, 16 Jun 2010 08:40:26 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27457.aspx</link><description>Hey, good to know. I've got RegexBuddy, will have a look at RegexMagic too.</description><pubDate>Wed, 16 Jun 2010 08:28:43 GMT</pubDate><dc:creator>Ivan George Borges</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27456.aspx</link><description>Using some kind of tool definitely makes using Regex easier.  The tool I use is Regex Buddy:&lt;br&gt;
&lt;br&gt;
[url]http://www.regexbuddy.com/[/url]&lt;br&gt;
&lt;br&gt;
The same company also has a new tool Regex Magic that looks promising:&lt;br&gt;
&lt;br&gt;
[url]http://www.regexmagic.com/[/url]&lt;br&gt;
&lt;br&gt;
It's nice to have choices. :D&lt;br&gt;
&lt;br&gt;</description><pubDate>Wed, 16 Jun 2010 07:49:08 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27455.aspx</link><description>Hey Edhy&lt;br&gt;
&lt;br&gt;
As you explore regex be sure to check out this free tool - Expresso&lt;br&gt;
&lt;br&gt;
[url]http://www.ultrapico.com/Expresso.htm[/url]&lt;br&gt;</description><pubDate>Wed, 16 Jun 2010 07:42:15 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27453.aspx</link><description>[quote][b]Greg McGuffey (06/15/2010)[/b][hr]I'd suggest that when you have some time, you might learn some more about regex...  :D[/quote]&lt;br&gt;
&lt;br&gt;
I agree, I have been wanted to get into RegEx since I was working with VFP and I have read some documentation about them but like you said it make take some deep testing to get the matching expressions correct.  &lt;br&gt;
&lt;br&gt;
This particular fix looks pretty simple, but when calling this method/function hundreds of time in a process it could take more time than using a properly RegEx expression, so I will explore it too this week.</description><pubDate>Tue, 15 Jun 2010 22:44:43 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27452.aspx</link><description>I'm glad you got it going. &lt;br&gt;
&lt;br&gt;
I'd suggest that when you have some time, you might learn some more about regex.  I just barely touched on the power of them. They can get very hairy to work with, but they have tons of power. They are also fast. And this is pretty much exactly what they were designed to do. The SF SyntaxEditor uses regex to do the color highlighting.  While the initial learning can be a bear, once you have an understanding of them, they turn many hard problems into rather simple ones.  :D</description><pubDate>Tue, 15 Jun 2010 22:36:10 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27451.aspx</link><description>Greg, once again, thanks for the RegEx samples but I decided to create a small function to parse the values.  Here is the code I came up with:&lt;br&gt;
[codesnippet]&lt;br&gt;
 Private OriginalValues() As String = {"AMDNY-0001253", "AMDNJ-0001253", "0001253", "XXHAM 1253", "1253"}&lt;br&gt;
    Private Sub ParseValues()&lt;br&gt;
        Dim sb As New System.Text.StringBuilder&lt;br&gt;
&lt;br&gt;
        '-- Loop each original value and separate the Alpha from the Numeric&lt;br&gt;
        For Each stringItem As String In OriginalValues&lt;br&gt;
            Dim CharacterEnumerator As CharEnumerator = stringItem.GetEnumerator&lt;br&gt;
&lt;br&gt;
            Dim AlphaValueCounter As Integer = 0&lt;br&gt;
            While (CharacterEnumerator.MoveNext())&lt;br&gt;
&lt;br&gt;
                If Char.IsDigit(CharacterEnumerator.Current) Then&lt;br&gt;
                    '-- If the current character is a digit then ignore the zero value&lt;br&gt;
                    If CharacterEnumerator.Current &lt;&gt; "0" Then&lt;br&gt;
                        ' If the current character is not a zero then we have the current position&lt;br&gt;
                        ' to split or in this case SubString() the original value&lt;br&gt;
                        Exit While&lt;br&gt;
                    End If&lt;br&gt;
                End If&lt;br&gt;
                AlphaValueCounter += 1&lt;br&gt;
            End While&lt;br&gt;
&lt;br&gt;
            '-- Create a string builder output to show the different values&lt;br&gt;
            sb.AppendLine("Original Value = " &amp; stringItem)&lt;br&gt;
            sb.AppendLine("Alpha value = " &amp; stringItem.Substring(0, AlphaValueCounter))&lt;br&gt;
            sb.AppendLine("Numeric value = " &amp; stringItem.Substring(AlphaValueCounter))&lt;br&gt;
            sb.AppendLine("---------------------------------------------")&lt;br&gt;
            sb.AppendLine()&lt;br&gt;
        Next&lt;br&gt;
        MessageBox.Show(sb.ToString)&lt;br&gt;
    End Sub&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
Then if you have this code in a form, you will call it like  Me.ParseValues() it will simply show a message box with all the original values and the parsed ones.  &lt;br&gt;
&lt;br&gt;
If anybody come up with a simpler approach, please let us know, it will be greatly appreciated. :hehe:</description><pubDate>Tue, 15 Jun 2010 18:26:22 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27450.aspx</link><description>Thanks Greg,&lt;br&gt;
&lt;br&gt;
I will investigate RegEx even though in my case I don't have a constant delimiter like in sample 3 and I need to get just the numeric part to do the calculations and generate new numbers to be added to the alpha part.  If I would have a delimiter I could use the String.Split() but I guess I will need to do a function to scan each character and test for IsNumeric() or Char.IsDigit() from right to left until an alpha is found then split the whole value.&lt;br&gt;
&lt;br&gt;
It would be really cool if a RegEx expression could get it right. :w00t:</description><pubDate>Tue, 15 Jun 2010 17:16:53 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27449.aspx</link><description>Whoops, code example got messed up because of less than/greater than signs:&lt;br&gt;
&lt;br&gt;
[codesnippet]Dim re As New Regex("(?&amp;lt;prodgroup&amp;gt;[A-Z]*)-(?&amp;lt;id&amp;gt;[0-9]*)")&lt;br&gt;
Dim mc As MatchCollection = re.Matches("AMDNY-0001253")&lt;br&gt;
Dim m As Match = mc(0)&lt;br&gt;
Dim prodGroup as Group = m.Groups("prodgroup")&lt;br&gt;
Dim idGroup as Group = m.Groups("id")&lt;br&gt;
&lt;br&gt;
MessageBox.Show(prodGroup.Value)&lt;br&gt;
MessageBox.Show(idGroup.Value)[/codesnippet]</description><pubDate>Tue, 15 Jun 2010 17:06:13 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: How to parse alphanumeric value?</title><link>http://forum.strataframe.net/FindPost27448.aspx</link><description>Regex!  It is a bit of a pain to learn, but it rocks at solving problems like this.  You'd use a regex patterns to match parts of an input string.&lt;br&gt;
This would match the first two examples. &lt;br&gt;
&lt;pre&gt;&lt;br&gt;
([A-Z]*)-([0-9]*)&lt;br&gt;
&lt;/pre&gt;&lt;br&gt;
This would match the third example:&lt;br&gt;
&lt;pre&gt;&lt;br&gt;
(0*)([0-9]*)&lt;br&gt;
&lt;/pre&gt;&lt;br&gt;
This would match the last example:&lt;br&gt;
&lt;pre&gt;&lt;br&gt;
([A-Z]*) ([0-9]*)&lt;br&gt;
&lt;/pre&gt;&lt;br&gt;
This would match either of the first two or the last one:&lt;br&gt;
&lt;pre&gt;&lt;br&gt;
([A-Z]*)(-| )([0-9]*)&lt;br&gt;
&lt;/pre&gt;&lt;br&gt;
&lt;br&gt;
Further, the parentheses are used to capture the matched text. Thus, in each of these examples you could then access the prefix separate from the suffix. I.e. with first pattern, and the input AMDNY-0001253 you could pull out AMDNY and 0001253 separately.&lt;br&gt;
&lt;br&gt;
I highly recommend RegExBuddy as a tool to help figure the patterns out.&lt;br&gt;
&lt;br&gt;
You then use the Regex object in .NET to work with this stuff:&lt;br&gt;
[codesnippet]Dim re As New Regex("(?&lt;prodgroup&gt;[A-Z]*)-(?&lt;delimiter&gt;[0-9]*)")&lt;br&gt;
Dim mc As MatchCollection = re.Matches("AMDNY-0001253")&lt;br&gt;
Dim m As Match = mc(0)&lt;br&gt;
Dim prodGroup as Group = m.Groups("prodgroup")&lt;br&gt;
Dim delimGroup as Group = m.Groups("delimiter")&lt;br&gt;
Dim idGroup as Group = m.Groups("id")&lt;br&gt;
&lt;br&gt;
MessageBox.Show(prodGroup.Value)&lt;br&gt;
MessageBox.Show(idGroup.Value)[/codesnippet]&lt;br&gt;
&lt;br&gt;
Regex is a big subject, but hopefully this will get you started.&lt;br&gt;</description><pubDate>Tue, 15 Jun 2010 17:03:26 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item></channel></rss>