社区
C#
帖子详情
字符串取值问题
fangfei306
2006-10-26 03:07:00
比如一个字符串“chinaren”,我要从右边开始取值得到"ren",
在VB或Asp中,
Right("chinaren",3) 即可得到ren
在C#中有没有什么方法,我找了半到也没找到相关的函数,只有跑到这里请求各位大虾的帮忙,万分感谢。
...全文
178
9
打赏
收藏
字符串取值问题
比如一个字符串“chinaren”,我要从右边开始取值得到"ren", 在VB或Asp中, Right("chinaren",3) 即可得到ren 在C#中有没有什么方法,我找了半到也没找到相关的函数,只有跑到这里请求各位大虾的帮忙,万分感谢。
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
9 条
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
打赏红包
fangfei306
2006-10-26
打赏
举报
回复
补充一下。
我的字符串条件是字符串长度是不定的,会变化,可能三位,可20位。
private string GetContent(string str,string start,string last,int n)
{
以下两行是ASP里的写法。我需要转化成C#
getcontent=Right(str,Len(str)-Instr(LCase(str),LCase(start))-Len(start)+1) ;
getcontent=Left(GetContent,Instr(LCase(GetContent),LCase(last))-1);
}
上面这两行代码表示的意思是:str 是得到的一串很长很长的字符串,start是开始查找的关键字,last是结束查找的关键字,n不作考虑,我要得到的是start与last两个关键字之间的一段字符串值 。
francis67
2006-10-26
打赏
举报
回复
string str1 = "chinaren";
Response.Write(str1.Substring(str1.Length-3));
fangfei306
2006-10-26
打赏
举报
回复
:),各位老兄很及时,非常感谢,你们所说的我都知道,
其实我要的是这样的效果:
private string GetContent(string str,string start,string last,int n)
{
以下两行是ASP里的写法。我需要转化成C#
getcontent=Right(str,Len(str)-Instr(LCase(str),LCase(start))-Len(start)+1) ;
getcontent=Left(GetContent,Instr(LCase(GetContent),LCase(last))-1);
}
liujia_0421
2006-10-26
打赏
举报
回复
string s = "Chinaren";
string subs= "ren";
int index = s.LastIndexOf(subs);
string re = s.Substring(index, subs.Length);
citypantheryan
2006-10-26
打赏
举报
回复
string s = "Chinaren";
string subs= "ren";
int index = s.LastIndexOf(subs);
string re = s.Substring(index, subs.Length);
应该加上转换大小写的方法,比较保险
zhangzengping
2006-10-26
打赏
举报
回复
反正就是 Substring(); IastIndexOf(), LastIndexOf(),Remove()的配合!
随心所欲吧!
yeerh
2006-10-26
打赏
举报
回复
string s = "Chinaren";
string subs= "ren";
int index = s.LastIndexOf(subs);
string re = s.Substring(index, subs.Length);
yeerh
2006-10-26
打赏
举报
回复
string s = "Chinaren";
int index = s.LastIndexOf("ren");
string re = s.Substring(index, subs.Length);
anuo06
2006-10-26
打赏
举报
回复
String myString = "abc";
bool test1 = String.Compare(myString.Substring(2, 1), "c") == 0; // This is true.
myString.Substring(3, 1); // This throws ArgumentOutOfRangeException.
bool test2 = String.Compare(myString.Substring(3, 0), String.Empty) == 0; // This is true.
相关推荐
Key值为
字符串
类型如何
取值
的
问题
Key值为
字符串
类型如何
取值
的
问题
IOS国际化
取值
问题
IOS国际化如果遇到NSLocalizedString
取值
问题
,可能原因是:
字符串
不是在 Localizable.strings 中定义的,在 InfoPlist.strings或其他strings文件中 定义
字符串
是取不到的 其他文件中需要使用NSLocalizedStringFromTable来获取。
【JS&JSON】JSON对象
取值
a,和
字符串
a比较不相等
【
问题
】 JSON对象
取值
"succeeded"和
字符串
常量"succeeded"判断相等为false。 代码: var obj = JSON.parse(data);//JSON
字符串
转对象 var stat = "\""+obj.submitStatus+"\""; console.log(typeof(stat)); console.log(stat); console.lo...
关于常量
项目代码中经常会需要定义一些常量
字符串
。比如一些默认
取值
。定义常量
字符串
的方法,首先想到的就是定义一个类属性,如:public static final String CONST = "1";调用的时候,当然就是:String cont1 = ConstantTest.CONST;但是这种方法有个
问题
。万一哪一天,常量的
取值
变化了,比如上文中的CONST
取值
变成了"2",那么...
mybatis
取值
${}不会特殊处理,有sql注入
问题
#{}会按
字符串
处理,加上单引号
发帖
C#
C#
.NET技术 C#
复制链接
扫一扫
10.8w+
社区成员
64.2w+
社区内容
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
帖子事件
创建了帖子
2006-10-26 03:07
社区公告
让您成为最强悍的C#开发者