المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : More elegant way then .Split(']');



C# Programming
05-18-2009, 03:12 PM
Dear All,

I have ListView full of things, but basically all the items have the same format :

TY223 [16]
TW121 [223]
...
...

If I want to substract the value 16 and TY223 from TY223 [16] , I go about it like this :


string[] a = itm.Value.ToString().Split('[');
string[] b = a[1].ToString().Split(']');

string first = a[1].ToString().Trim();
string second = b[0].ToString().Trim();

This works fine, however I'm only after the value 16. Is there a more elegant way of extracting this value from the item, instead of using .Split()

Kind regards,