如:‘13:金佛idjiorej男接口 24:发美女撒离开覅的342 24:回复ik平234 13:发挥哦很热 13:北方及卡拉是分(234 ’
内容除13:和24: 这两个是定值,其他都不确定,13:和24:位置也不固定
我需要取得’ 金佛idjiorej男接口 ,发挥哦很热,北方及卡拉是分(234 ‘的数组
请问该怎么弄啊?谢谢 要C#的……明天上班来结贴。
内容除13:和24: 这两个是定值,其他都不确定,13:和24:位置也不固定
我需要取得’ 金佛idjiorej男接口 ,发挥哦很热,北方及卡拉是分(234 ‘的数组
请问该怎么弄啊?谢谢 要C#的……明天上班来结贴。
本内容用 CSDN小秘书 回复
每天回帖即可获得10分可用分!
********************************************************
[/align]
string[] arr = mystr.Split(new string[] { "13:", "24:" }, StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine(arr.Length);
if (arr.Length == 5)
{
Console.WriteLine(arr[0]);
Console.WriteLine(arr[3]);
Console.WriteLine(arr[4]);
}[align=center]********************************************************
本内容用 CSDN小秘书 回复
每天回帖即可获得10分可用分!
********************************************************
[/align]
string[] str = Regex.Split( "你的字符串", "(13|24):", RegexOptions.IgnoreCase );
//或者
string[] str = "你的字符串".Split( new string[] { "13:", "24:" }, StringSplitOptions.RemoveEmptyEntries );
static void Main(string[] args)
{
string s = "13:金佛idjiorej男接口 24:发美女撒离开覅的342 24:回复ik平234 13:发挥哦很热 13:北方及卡拉是分(234 ";
string[] ss = s.Split(new string[] { "13:" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < ss.Length; i++)
{
ss[i] = ss[i].Substring(0, ss[i].IndexOf(' ') - 1);
}
foreach (string item in ss)
{
Console.WriteLine(item);
}
}
txt = txt.Replace("13:", ",");
txt = txt.Replace("24:", ",");
string mystr = "13:金佛idjiorej男接口 24:发美女撒离开覅的342 24:回复ik平234 13:发挥哦很热 13:北方及卡拉是分(234 ’";
string[] arr = mystr.Split(new string[] { "13:", "24:" }, StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine(arr.Length);
if (arr.Length == 5)
{
Console.WriteLine(arr[0]);
Console.WriteLine(arr[3]);
Console.WriteLine(arr[4]);
}这样可以达到你要的效果
public static string GetFirstString(string stringToSub, int length)
{
Regex regex = new Regex("[\u4e00-\u9fa5]+", RegexOptions.Compiled);
char[] stringChar = stringToSub.ToCharArray();
StringBuilder sb = new StringBuilder();
int nLength = 0;
bool isCut=false;
for(int i = 0; i < stringChar.Length; i++)
{
if (regex.IsMatch((stringChar[i]).ToString()))
{
sb.Append(stringChar[i]);
nLength += 2;
}
else
{
sb.Append(stringChar[i]);
nLength = nLength + 1;
} if (nLength > length)
{
isCut=true;
break;
}
}
if(isCut)
return sb.ToString()+"..";
else
return sb.ToString();
}
foreach(string s in str.Split(' '))
{
再split14: 24:保存到dictinary中
}
string pattern = "(?<=13:).*?(?=\\s*(13:|24:|$))";
MatchCollection ms = Regex.Matches(s, pattern);
foreach (Match m in ms)
{
Console.WriteLine("【{0}】", m.Value);
}
string pattern = @"(?<=13:)\S*(?<!24:)"; MatchCollection ms = Regex.Matches(s, pattern); foreach (Match m in ms)
{
Console.WriteLine("【{0}】", m.Value);
}
19楼的这位,如果正则用这个。。那么当需要获取的内容中含有空格,或者13和24前没有空格的话就会发生错误。。当然,如果不会出现以上情况的话那就是正确的。。
str= str.Replace("13:", "");
str = str.Replace("24:", "");
this.textBox2.Text = str.ToString();