0
public ActionResult MusteriArama(string SeciliMusteri)
{
    if (SeciliMusteri != null)
    {
       foreach (var x in SeciliMusteri.Split(';'))
       {                    

       }
    }
}

SeciliMusteri 是“公司;50”

我想拿“50”并保留它,我该怎么做?

4

2 回答 2

0

Assuming this is C# (ASP.NET), or an equivalent method is available:

If you don't need to actually split all the parts, you can use LastIndexOf instead:

SeciliMusteri.Substring(SeciliMusteri.LastIndexOf(';') + 1)

Alternatively, if iterating through has a purpose, just keep saving the current element as you iterate, the last saved one will be by definition the final one:

string lastOne = null;

if (SeciliMusteri != null)
{
    foreach (var x in SeciliMusteri.Split(';'))
    {               
        DoSomethingWith(x);

        lastOne = x;
    }
}
于 2013-07-30T10:47:35.497 回答
0

you can do:

string split[] = SeciliMusteri.Split(';');
string myPart = split[1];

or

string myPart = split[spit.Length - 1];
于 2013-07-30T10:48:24.843 回答