Code:
public string Split(string s)
// s= "diễn //đàn vnzoom là nơi //để chia sẻ kiến thức và kinh //nghiệm học tập"
{
string[] sep = { "//" };
string[] sep1 = { " " };
string[] t1 = s.Split(sep, StringSplitOptions.RemoveEmptyEntries);
string res = "";
for (int i=1; i < t1.Length; i++)
{
string[] t2 = t1[i].Split(sep1, StringSplitOptions.RemoveEmptyEntries);
if (t2.Length > 0)
{
if (res.Length > 0)
{
res += "//";
}
res += t2[0];
}
}
return res;
} //
Cái này còn tùy vào cấu trúc của chuỗi mà phân tích..Tớ thường dùng hàm split trong xử lý chuỗi.
---------- Bài thêm lúc 11:32 ---------- Bài trước là lúc 11:21 ----------
Code:
public string Split(string s)
// s= "diễn //đàn vnzoom là nơi //để chia sẻ kiến thức và kinh //nghiệm học tập"
{
string res = "";
int i = s.IndexOf("//");
while ( i >= 0)
{
if (res.Length > 0)
{
res += "//";
}
res += s.Substring(i + 2, s.IndexOf(" ", i + 2)-(i+2));
i = s.IndexOf("//", i+2 + (s.IndexOf(" ", i + 2)-(i+2)));
}
return res;
} Cách này hơi rối hơn tí