c#把字符串按格式分割成两部分
update spy_customer_information set ORDER_PRIORITY_NEW = 'C' where order_id='gg773103'***gg773103 把这个字符串按中间的***分割成两部分,str1=update spy_customer_information set ORDER_PRIORITY_NEW = 'C' where order_id='gg773103'
str2 = gg773103
补充:把上面这个字符串按中间的***分割成连个字符串
答案:string s1="update spy_customer_information set ORDER_PRIORITY_NEW = 'C' where order_id='gg773103'***gg773103";
s1.Substring(0, s1.IndexOf('*'));
s1.Substring(s1.LastIndexOf('*') + 1);
其他:没看明白什么意思 直接用替换 replace()方法
把***替换成" or str2 = "
你这句话看起来应该是sql语句,记得替换之后,加上连接词
应该是 or
最后应该变成
where order_id='gg773103'
or str2 = gg773103 string str=" order_id='gg773103'***gg773103";
string str1=str.Split( new char[]{'*','*','*'},StringSplitOptions.RemoveEmptyEntries)[0];
string str2=str.Split( new char[]{'*','*','*'},StringSplitOptions.RemoveEmptyEntries)[1]; 百度找split这个方法,有解释 你的意思是:要把“update spy_customer_information set ORDER_PRIORITY_NEW = 'C' where order_id='gg773103'***gg773103 ” 分成后面两个????
如果是这样,可以采用以下办法:
把“update spy_customer_information set ORDER_PRIORITY_NEW = 'C' where order_id='gg773103'***gg773103 ” 赋值给一个字符串变量,假如变量名为str
方法一:用分组方式
string[] strszu=str.split('***')
str1=str[0];
str2=str[1];
方法二:读取“***”在str的位置index,str1=str.substring(0,index);
str2=str.substring(index+3,str.length-index-3); string str = @"gg773103'***gg773104";
string[] strs=new string[2];
strs = str.Split(new char[3] { '*', '*', '*' });
分割结果
strs[0].string()=“gg773103”
strs[1].string()="gg773104" order_id.split(new string{"***"},stringsplitoption.removeempty);
嗯..
手码应该打错了.不过你应该理解意思了
上一个:asp.net c# 问题,我的textbox 没有MouseLeave事件,怎么办?
下一个:求一个c#小程序,每秒向数据库表中自动插入一条数据。