读书人

C#中用什么函数可以返回某一字符串从另

发布时间: 2012-03-09 21:42:55 作者: rapoo

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
[解决办法]
没有直接的函数,这个不就行了吗?

也不复杂吧..

读书人网 >C#

热点推荐