Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to remove string like 23x45 in vb6 how to do it

What I have tried:

VB
Regex regex = new Regex(@"^(?<leftpart>[\d]?)/(?<rightpart>[\d]?)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
Match m = regex.Match(yourString);
 
if (m.Success)
{
   string left = m.Groups["LeftPart"].Value;
   string right = m.Groups["RightPart"].Value;
 
   while (left.Length < 4)
      left.Insert(0, "0");
 
   while (right.Length < 2)
      right.Insert(0, "0");
}
else
{
   // Handle error
}
Posted
Updated 17-Feb-16 22:45pm
v2

1 solution

Try changing the regex:
^(?<leftpart>[\d]+)(?<Symbols>[^\d]+)(?<rightpart>[\d]+)$
 
Share this answer
 
Comments
Matt T Heffron 18-Feb-16 13:59pm    
The character class [] are unnecessary:
[\d]+ can be just \d+
[^\d]+ can be just \D+
OriginalGriff 18-Feb-16 14:12pm    
You're right - I needed more caffeine...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900