public ActionResult MusteriArama(string SeciliMusteri)
{
if (SeciliMusteri != null)
{
foreach (var x in SeciliMusteri.Split(';'))
{
}
}
}
SeciliMusteri 是“公司;50”
我想拿“50”并保留它,我该怎么做?
public ActionResult MusteriArama(string SeciliMusteri)
{
if (SeciliMusteri != null)
{
foreach (var x in SeciliMusteri.Split(';'))
{
}
}
}
SeciliMusteri 是“公司;50”
我想拿“50”并保留它,我该怎么做?
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;
}
}
you can do:
string split[] = SeciliMusteri.Split(';');
string myPart = split[1];
or
string myPart = split[spit.Length - 1];