PDA

View Full Version : انتخاب کارکترها از یک رشته



alonemm
چهارشنبه 06 مرداد 1389, 13:55 عصر
باسلام:
من یک رشته دارم دریک متغییر:
a="my name is majid" "
حالا میخام 4 کاراکتر از سمت چپ رو تویک متغییر و 5 کاراکتر از سمت راست رو توی یک متغییر دیگه و از کاراکتر 3 تا 7 رو توی متغییر شماره سه بریزم.
به زبان سی شارپ.

amirjalili
چهارشنبه 06 مرداد 1389, 14:17 عصر
تمام جواب شما :


string str = "A silly sentence used for silly purposes.";
System.Console.WriteLine("'{0}'",str);

bool test1 = str.StartsWith("a silly");
System.Console.WriteLine("starts with 'a silly'? {0}", test1);

bool test2 = str.StartsWith("a silly", System.StringComparison.OrdinalIgnoreCase);
System.Console.WriteLine("starts with 'a silly'? {0} (ignoring case)", test2);

bool test3 = str.EndsWith(".");
System.Console.WriteLine("ends with '.'? {0}", test3);

int first = str.IndexOf("silly");
int last = str.LastIndexOf("silly");
string str2 = str.Substring(first, last - first);
System.Console.WriteLine("between two 'silly' words: '{0}'", str2);


http://msdn.microsoft.com/en-us/library/ms228630.aspx

alonemm
چهارشنبه 06 مرداد 1389, 14:52 عصر
من که اینو متوج نشدم.
با توجه به رشته ای که دادم و چیزایی که خاستم یک مثال بزندید.با تشکر.