日期:2014-05-20  浏览次数:20690 次

C#中用什么函数可以返回某一字符串从另一字符串的左/右侧开始算起第一次出现的位置
例如,VB中:   Dim   strsde   As   String
                      strsde= "456123.25 "
                      Dim   pos   As   Long
                      pos   =   InStrRev(strsde,   ". ")
其中,InStrRev函数:返回某一字符串从另一字符串的右侧开始算起第一次出现的位置.

在C#里应怎样实现       大侠帮忙啊......

------解决方案--------------------
string strsde = "456123.25 ";
long pos = strsde.IndexOf( ". ");
------解决方案--------------------
pos = fileName.IndexOf( ". ");
------解决方案--------------------
IndexOf
LastIndexOf
------解决方案--------------------
IndexOf
------解决方案--------------------
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.

------解决方案--------------------
String.IndexOf(string)
------解决方案--------------------
lastIndexOf();
------解决方案--------------------
似乎没有...

用LastIndexOf不能实现吗?

把你的需求说一下..
------解决方案--------------------
IndexOf
LastIndexOf

------解决方案--------------------
string1.IndexOf(string2)
------解决方案--------------------
str.indexOf(str, ". ")
------解决方案--------------------
是这个意思吗?

string str = "aaa.bbb.ccc ";
int index = str.Length-1 - str.LastIndexOf( ". ");

输出index是3
------解决方案--------------------
没有直接的函数,这个不就行了吗?

也不复杂吧..