regarding separte string in c#

csharp Antarctica
  • 12 years ago

    hi friends ......

    i m new in this field...

    i have problem regarding c# code..

    i have string like this string text="1_9860214285_QCIRS Canned /Y=2008/MT=ODI/V=SydneyCricketGround/T=INDIA Vs AUSTRALIA/G=*/ID=9/F=*/C=*/P=*/";

    i want seaprate that underscore ..

    means i want msgid=1;

                       mobileno=9860214285;

                      mobilequery="QCIRS Canned /Y=2008/MT=ODI/V=SydneyCricketGround/T=INDIA Vs AUSTRALIA/G=*/ID=9/F=*/C=*/P=*/";

    in this format;

    plz anyone help me or share code for this..

     

  • 12 years ago

    String text=@"1_9860214285_QCIRS Canned /Y=2008/MT=ODI/V=SydneyCricketGround/T=INDIA Vs AUSTRALIA/G=*/ID=9/F=*/C=*/P=*/";

    String[] tokens = text.Split(new char[]{'_'});

    String msgid= tokens[0];
    String mobileno=tokens[1];
    String mobilequery=tokens[2];

    You may also use regex match or combination of String.IndexOf and String.SubString methods

  • 12 years ago

    Hi Parshant,

    Here is the simple code that will solve your problem.

     string text = "1_9860214285_QCIRS Canned /Y=2008/MT=ODI/V=SydneyCricketGround/T=INDIA Vs AUSTRALIA/G=*/ID=9/F=*/C=*/P=*/";
                string [] split = text.Split(new Char [] {'_'});
                string[] temp = new string[3];
                int a = 0;

                foreach (string s in split)
                {
                    tempAngel = s;
                    a++;
                }
                label1.Text = "Message ID: " + temp[0];
                label2.Text = "Mobile No: " + temp[1];
                label3.Text = "Mobile Query: " + temp[2];
     

  • 12 years ago

    thnx dude ......

    u r code really helpful.....

    i got output asper my requirement.............

    once agin thx.......................byyyyyyyyyyyy

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Beware of bugs in the above code; I have only proved it correct, not tried it.” - Donald Knuth