您的位置:程序门 -> .net技术 -> c#



c#中用什么函数可以返回某一字符串从另一字符串的左/右侧开始算起第一次出现的位置


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


c#中用什么函数可以返回某一字符串从另一字符串的左/右侧开始算起第一次出现的位置[已结贴,结贴人:pqy_20]
发表于:2007-01-16 10:45:12 楼主
例如,vb中:   dim   strsde   as   string
                      strsde= "456123.25 "
                      dim   pos   as   long
                      pos   =   instrrev(strsde,   ". ")
其中,instrrev函数:返回某一字符串从另一字符串的右侧开始算起第一次出现的位置.

在c#里应怎样实现       大侠帮忙啊......
发表于:2007-01-16 10:47:441楼 得分:2
string   strsde   =   "456123.25 ";
long   pos   =   strsde.indexof( ". ");
发表于:2007-01-16 10:48:442楼 得分:2
pos   =   filename.indexof( ". ");
发表于:2007-01-16 10:53:293楼 得分:2
indexof
lastindexof
发表于:2007-01-16 11:07:174楼 得分:2
indexof
发表于:2007-01-16 12:14:445楼 得分:2
public   int   lastindexof(string   value)
        member   of   system.string

summary:
reports   the   index   position   of   the   last   occurrence   of   a   specified   system.string   within   this   instance.

parameters:
value:   a   system.string   to   seek.  

returns:
the   index   position   of   value   if   that   string   is   found,   or   -1   if   it   is   not.   if   value   is   system.string.empty,   the   return   value   is   the   last   index   position   in   value.
发表于:2007-01-16 12:45:306楼 得分:1
string.indexof(string)
发表于:2007-01-16 13:28:407楼 得分:2
lastindexof();
发表于:2007-01-16 16:51:058楼 得分:0
indexof\lastindexof都是从左算起     怎样从右开始算起
发表于:2007-01-16 19:50:559楼 得分:1
似乎没有...

用lastindexof不能实现吗?

把你的需求说一下..
发表于:2007-01-16 20:06:1610楼 得分:1
indexof
lastindexof
发表于:2007-01-16 20:19:4411楼 得分:1
string1.indexof(string2)
发表于:2007-01-16 20:23:1612楼 得分:1
str.indexof(str, ". ")
发表于:2007-01-17 10:06:5713楼 得分:0
lastindexof返回的是最后一个匹配项的索引位置

pos   =   instrrev(strsde,   ". ")
像instrrev函数:返回某一字符串从另一字符串的右侧开始算起第一次出现的位置
发表于:2007-01-17 10:15:4414楼 得分:2
是这个意思吗?

string   str   =   "aaa.bbb.ccc ";
                        int   index   =   str.length-1   -   str.lastindexof( ". ");

输出index是3
发表于:2007-01-17 12:16:4215楼 得分:0
对     也是这么做得     就是想不知道c#里有没有更好的实现方法
发表于:2007-01-17 12:42:1716楼 得分:1
没有直接的函数,这个不就行了吗?

也不复杂吧..


快速检索

最新资讯
热门点击