是想把英文句子分成单词,去掉'.'这句号的时候是可以的,但是一旦要去掉','(逗号)和'"'(引号)就出问题了,
比如一句句子:Recently, the ministries of agriculture, ……
这样子出来的结果只有“Recently”,后面的全都没了。感觉是跳掉了。
是','、'"'有什么特别的用途的么?==============我是CJ的分隔线=====================代码是这个样子的:tempst[]就是存放诸如“Recently,”,“the”的数组了
(不要嫌我罗嗦= =|||)
但是出来的结果就是Recently后面什么都没有foreach(string stemp in tempst)
{
i = 0;
char[] chtemp1 = stemp.ToCharArray();
char[] chtemp2 = new char[stemp.Length];
foreach(char ch1 in chtemp1)
{
if(ch1=='.' || ch1==',' || ch1=='"')
{
}
else
chtemp2[i++] = ch1;
}
string sss = new string(chtemp2);
string sss1 = sss.Trim();
//print_text += ((MyItem)htEC[sss]).Explain1 + "\n";
print_text += sss1 + "\n";
chtemp1 = null;
chtemp2 = null;
// if(htEC.ContainsKey(sss))
// {
// item = (MyItem)htEC[sss];
// print_text += item1.Explain1 + "\n";
// }
}
比如一句句子:Recently, the ministries of agriculture, ……
这样子出来的结果只有“Recently”,后面的全都没了。感觉是跳掉了。
是','、'"'有什么特别的用途的么?==============我是CJ的分隔线=====================代码是这个样子的:tempst[]就是存放诸如“Recently,”,“the”的数组了
(不要嫌我罗嗦= =|||)
但是出来的结果就是Recently后面什么都没有foreach(string stemp in tempst)
{
i = 0;
char[] chtemp1 = stemp.ToCharArray();
char[] chtemp2 = new char[stemp.Length];
foreach(char ch1 in chtemp1)
{
if(ch1=='.' || ch1==',' || ch1=='"')
{
}
else
chtemp2[i++] = ch1;
}
string sss = new string(chtemp2);
string sss1 = sss.Trim();
//print_text += ((MyItem)htEC[sss]).Explain1 + "\n";
print_text += sss1 + "\n";
chtemp1 = null;
chtemp2 = null;
// if(htEC.ContainsKey(sss))
// {
// item = (MyItem)htEC[sss];
// print_text += item1.Explain1 + "\n";
// }
}
程序:
static void Main(string[] args)
{ string [] tempst = new string [] {"Recently .,.,.,.,.the ministries of..... agriculture,"}; string print_text = null;
foreach(string stemp in tempst)
{
int i = 0;
char[] chtemp1 = stemp.ToCharArray();
char[] chtemp2 = new char[stemp.Length];
foreach(char ch1 in chtemp1)
{
if(ch1=='.' || ch1==',' || ch1=='"')
{
}
else
chtemp2[i++] = ch1;
}
string sss = new string(chtemp2);
string sss1 = sss.Trim();
//print_text += ((MyItem)htEC[sss]).Explain1 + "\n";
print_text += sss1 + "\n";
chtemp1 = null;
chtemp2 = null;
Console.WriteLine(print_text); }
Console.ReadLine(); }输出:
Recent the ministries of griculture
{ string [] tempst = new string [] {"Recently .,",".,.,.,.the ministries of..... agriculture,","helios"}; string print_text = null;
foreach(string stemp in tempst)
{
int i = 0;
char[] chtemp1 = stemp.ToCharArray();
char[] chtemp2 = new char[stemp.Length];
foreach(char ch1 in chtemp1)
{
if(ch1=='.' || ch1==',' || ch1=='"')
{
}
else
chtemp2[i++] = ch1;
}
string sss = new string(chtemp2);
string sss1 = sss.Trim();
//print_text += ((MyItem)htEC[sss]).Explain1 + "\n";
print_text += sss1 + "\n";
chtemp1 = null;
chtemp2 = null;
}
Console.WriteLine(print_text);
Console.ReadLine(); }
}output:Recently
the ministries of agriculture
helios
String.Split (Char[]) 返回包含此实例中的子字符串(由指定 Char 数组的元素分隔)的 String 数组。
String.Split (Char[], Int32) 返回包含此实例中的子字符串(由指定 Char 数组的元素分隔)的 String 数组。参数指定返回的子字符串的最大数量。
String.Split (Char[], StringSplitOptions) 返回包含此字符串中的子字符串(由指定的 Char 数组的元素分隔)的 String 数组。参数指定是否返回空数组元素。
String.Split (String[], StringSplitOptions) 返回包含此字符串中的子字符串(由指定的 String 数组的元素分隔)的 String 数组。参数指定是否返回空数组元素。
String.Split (Char[], Int32, StringSplitOptions) 返回包含此字符串中的子字符串(由指定的 Char 数组的元素分隔)的 String 数组。参数指定要返回子字符串的最大数量,以及是否要返回空数组元素。
String.Split (String[], Int32, StringSplitOptions)
最后还是只好用split的办法= =|||