I need to sort the string based on the following conditions...
here is the input "100AP12345678"
need output like 100 in one string AP in another and 1234567890 in another..
I did like below
protected void Button1_Click(object sender, EventArgs e)
{
var numAlpha = new Regex("(?<Numeric>[0-9]+)(?<Alpha>[a-zA-Z]*)");
var input=TextBox1.Text;
var match = numAlpha.Match(TextBox1.Text);
var Amount = match.Groups["Numeric"].Value;
var Operator = match.Groups["Alpha"].Value;
var index = Operator.Substring(Operator.Length - 1);
var MobileNum = input.Substring(input.IndexOf(index) + 1);
var kk = numAlpha.Match(MobileNum).Groups["Alpha"].Value;
if ((Operator.Length > 2) & ((numAlpha.Match(MobileNum).Groups["Alpha"].Value).Length != 0) || (MobileNum.Length > 10))
{
Label1.Text = Amount;
Label3.Text = "invalid MobileNum";
Label2.Text = "invalid operator";
}
else if (((numAlpha.Match(MobileNum).Groups["Alpha"].Value).Length != 0) & (MobileNum.Length > 10))
{
Label1.Text = Amount;
Label2.Text = Operator;
Label3.Text = "invalid MobileNum";
}
else if (Operator.Length > 2)
{
Label1.Text = Amount;
Label2.Text = "invalid operator";
Label3.Text = MobileNum;
}
else
{
Label1.Text = Amount;
Label2.Text = Operator;
Label3.Text = MobileNum;
}
}
first charcaters i.e numbers are rupees and next two are operator and the remaining are mobile number
conditions:
1.amount will have no limitation
2.operator should be two characters
3.mobileNum should not exceed 10
the above code works good
but two limitations 1. when I am passing input starting with alphabets it doesnt work
like ab1001234567890
as I have given regex function as numbers and alphabets
and second limitation is
when i Pass operator like aba its not showing invalid operator as I used Substring..
Everything works good if I pass input like
100VD9441239494
here two limitations in the code
1.If I pass VD1009441239494 doesnt work n achevie my requirements
- if i pass reapareted characters in operartor like
100VDV9441239494 not getting perfect output as I used Substring
lk109032030002misses the first part.