初学C#,有个关于string的问题?

hbjxx638 2009-03-13 01:13:21
在C++里面,CString有个方法Tokenize,在C#里面怎么实现这个效果?
比如一个string是"test.me",我怎么通过"."来得到它后面的字符串,即"me"?
...全文
74 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2009-03-13
  • 打赏
  • 举报
回复
string strE= str.Substring(str.LastIndexOf(".")+1);
ojwftded 2009-03-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hhxxcj 的回复:]
还有一个更简单的方法
string[] Str_Value = test.Split(new char[] { '.' });

想要第几个就第几个
[/Quote]
正解
Teng_s2000 2009-03-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 hhxxcj 的回复:]
还有一个更简单的方法
string[] Str_Value = 这个是字符串变量.Split(new char[] { '.' });

想要第几个就第几个
[/Quote]

对,就是这样分割字符串为字符串数组
然后Str_Value[index]就可以获取了啊
liujiayu10 2009-03-13
  • 打赏
  • 举报
回复
string str="test.me";
str=str.Substring(str.IndexOf(".")+1);
Cherishny 2009-03-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 hbjxx638 的帖子:]
在C++里面,CString有个方法Tokenize,在C#里面怎么实现这个效果?
比如一个string是"test.me",我怎么通过"."来得到它后面的字符串,即"me"?
[/Quote]

// 摘要:
// 返回包含此实例中的子字符串(由指定 System.Char 数组的元素分隔)的 System.String 数组。
//
// 参数:
// separator:
// 分隔此实例中子字符串的 Unicode 字符数组、不包含分隔符的空数组或 null。
//
// 返回结果:
// 一个数组,其元素包含此实例中的子字符串,这些子字符串由 separator 中的一个或多个字符分隔。有关更多信息,请参见备注部分。
public string[] Split(params char[] separator);
CraxyMouse 2009-03-13
  • 打赏
  • 举报
回复
string xx="test.me
x=xx.substring(xx.indexof("."));
hhxxcj 2009-03-13
  • 打赏
  • 举报
回复
还有一个更简单的方法
string[] Str_Value = 这个是字符串变量.Split(new char[] { '.' });

想要第几个就第几个
zgke 2009-03-13
  • 打赏
  • 举报
回复
C#里 Split
string[] _Text = "test.me".Split('.');
hhxxcj 2009-03-13
  • 打赏
  • 举报
回复
还有一个更简单的方法
string[] Str_Value = test.Split(new char[] { '.' });

想要第几个就第几个
whoami333 2009-03-13
  • 打赏
  • 举报
回复
string str1="test.me";
str1=str1.Substring(str1.IndexOf(".")+1);
hhxxcj 2009-03-13
  • 打赏
  • 举报
回复
可以用IndexOf和Substring()来得到

110,547

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧