字符串为:张三先生
我要截取张三,注意,名称不是固定的,或者为王麻子(先生),截取王麻子
求大虾帮忙,急,在线等。。。。。。。。。。。。。。。。。。
12 个解决方案
#1
先找到 先 的位置 再截取
#2
具体的代码是怎么的呢,小弟初学,麻烦指教以下,谢谢
#3
left(字符串,pos(字符串,'张三') -1)
#4
名字只是我举的一个例子,是我从数据库中取出来的,可能是XXX先生,就是把先生去掉,保留前面的子串就是了
#5
left(str,pos(str,'先生') -1)
#6
最好名称要规范如××先生
如果名称中包含( -- 等字符
你是要先对字符进行检测,判断是否为汉字,取出不为汉字的位置 然后用left(str,位置 -1)
如果名称中包含( -- 等字符
你是要先对字符进行检测,判断是否为汉字,取出不为汉字的位置 然后用left(str,位置 -1)
#7
我的代码:
long ll_row,ll_rowcount
string ls_sname,ls_name,ls_str
int i
ll_rowcount = dw_1.rowcount()
for ll_row = 1 to ll_rowcount step +1
ls_sname = dw_1.getitemstring(ll_row, "LIANXIREN")
ls_str = dw_1.getitemstring(ll_row,"MINGCHENG")
if pos(ls_sname,'先生') > 0 then
ls_name = left(ls_sname,pos(ls_sname,'先生') -1)
// i = lastpos('先',ls_sname)
// ls_name = mid(ls_sname,1,i)
update customer_conf set lianxiren = :ls_name where mingcheng = :ls_str and lianxiren = :ls_sname;
commit;
next
运行后:
Error c0031:Syntax error
long ll_row,ll_rowcount
string ls_sname,ls_name,ls_str
int i
ll_rowcount = dw_1.rowcount()
for ll_row = 1 to ll_rowcount step +1
ls_sname = dw_1.getitemstring(ll_row, "LIANXIREN")
ls_str = dw_1.getitemstring(ll_row,"MINGCHENG")
if pos(ls_sname,'先生') > 0 then
ls_name = left(ls_sname,pos(ls_sname,'先生') -1)
// i = lastpos('先',ls_sname)
// ls_name = mid(ls_sname,1,i)
update customer_conf set lianxiren = :ls_name where mingcheng = :ls_str and lianxiren = :ls_sname;
commit;
next
运行后:
Error c0031:Syntax error
#8
晕,忘了end if了,嘿嘿,好了,马上给分
#9
当然会语法错误
if pos(ls_sname,'先生') > 0 then
ls_name = left(ls_sname,pos(ls_sname,'先生') -1)
// i = lastpos('先',ls_sname)
// ls_name = mid(ls_sname,1,i)
end if//缺少
update customer_conf set lianxiren = :ls_name where mingcheng = :ls_str and lianxiren = :ls_sname;
commit;
if pos(ls_sname,'先生') > 0 then
ls_name = left(ls_sname,pos(ls_sname,'先生') -1)
// i = lastpos('先',ls_sname)
// ls_name = mid(ls_sname,1,i)
end if//缺少
update customer_conf set lianxiren = :ls_name where mingcheng = :ls_str and lianxiren = :ls_sname;
commit;
#10
messagebox('',ls_name)看看是什么
#11
long ll_row,ll_rowcount
string ls_sname,ls_name,ls_str
int i
ll_rowcount = dw_1.rowcount()
for ll_row = 1 to ll_rowcount step +1
ls_sname = dw_1.getitemstring(ll_row, "LIANXIREN")
ls_str = dw_1.getitemstring(ll_row,"MINGCHENG")
if pos(ls_sname,'先生') > 0 then
ls_name = left(ls_sname,pos(ls_sname,'先生') -1)
update customer_conf set lianxiren = :ls_name where mingcheng = :ls_str and lianxiren = :ls_sname;
commit;
end if
next
dw_1.retrieve()
string ls_sname,ls_name,ls_str
int i
ll_rowcount = dw_1.rowcount()
for ll_row = 1 to ll_rowcount step +1
ls_sname = dw_1.getitemstring(ll_row, "LIANXIREN")
ls_str = dw_1.getitemstring(ll_row,"MINGCHENG")
if pos(ls_sname,'先生') > 0 then
ls_name = left(ls_sname,pos(ls_sname,'先生') -1)
update customer_conf set lianxiren = :ls_name where mingcheng = :ls_str and lianxiren = :ls_sname;
commit;
end if
next
dw_1.retrieve()
#12
现在好了
#1
先找到 先 的位置 再截取
#2
具体的代码是怎么的呢,小弟初学,麻烦指教以下,谢谢
#3
left(字符串,pos(字符串,'张三') -1)
#4
名字只是我举的一个例子,是我从数据库中取出来的,可能是XXX先生,就是把先生去掉,保留前面的子串就是了
#5
left(str,pos(str,'先生') -1)
#6
最好名称要规范如××先生
如果名称中包含( -- 等字符
你是要先对字符进行检测,判断是否为汉字,取出不为汉字的位置 然后用left(str,位置 -1)
如果名称中包含( -- 等字符
你是要先对字符进行检测,判断是否为汉字,取出不为汉字的位置 然后用left(str,位置 -1)
#7
我的代码:
long ll_row,ll_rowcount
string ls_sname,ls_name,ls_str
int i
ll_rowcount = dw_1.rowcount()
for ll_row = 1 to ll_rowcount step +1
ls_sname = dw_1.getitemstring(ll_row, "LIANXIREN")
ls_str = dw_1.getitemstring(ll_row,"MINGCHENG")
if pos(ls_sname,'先生') > 0 then
ls_name = left(ls_sname,pos(ls_sname,'先生') -1)
// i = lastpos('先',ls_sname)
// ls_name = mid(ls_sname,1,i)
update customer_conf set lianxiren = :ls_name where mingcheng = :ls_str and lianxiren = :ls_sname;
commit;
next
运行后:
Error c0031:Syntax error
long ll_row,ll_rowcount
string ls_sname,ls_name,ls_str
int i
ll_rowcount = dw_1.rowcount()
for ll_row = 1 to ll_rowcount step +1
ls_sname = dw_1.getitemstring(ll_row, "LIANXIREN")
ls_str = dw_1.getitemstring(ll_row,"MINGCHENG")
if pos(ls_sname,'先生') > 0 then
ls_name = left(ls_sname,pos(ls_sname,'先生') -1)
// i = lastpos('先',ls_sname)
// ls_name = mid(ls_sname,1,i)
update customer_conf set lianxiren = :ls_name where mingcheng = :ls_str and lianxiren = :ls_sname;
commit;
next
运行后:
Error c0031:Syntax error
#8
晕,忘了end if了,嘿嘿,好了,马上给分
#9
当然会语法错误
if pos(ls_sname,'先生') > 0 then
ls_name = left(ls_sname,pos(ls_sname,'先生') -1)
// i = lastpos('先',ls_sname)
// ls_name = mid(ls_sname,1,i)
end if//缺少
update customer_conf set lianxiren = :ls_name where mingcheng = :ls_str and lianxiren = :ls_sname;
commit;
if pos(ls_sname,'先生') > 0 then
ls_name = left(ls_sname,pos(ls_sname,'先生') -1)
// i = lastpos('先',ls_sname)
// ls_name = mid(ls_sname,1,i)
end if//缺少
update customer_conf set lianxiren = :ls_name where mingcheng = :ls_str and lianxiren = :ls_sname;
commit;
#10
messagebox('',ls_name)看看是什么
#11
long ll_row,ll_rowcount
string ls_sname,ls_name,ls_str
int i
ll_rowcount = dw_1.rowcount()
for ll_row = 1 to ll_rowcount step +1
ls_sname = dw_1.getitemstring(ll_row, "LIANXIREN")
ls_str = dw_1.getitemstring(ll_row,"MINGCHENG")
if pos(ls_sname,'先生') > 0 then
ls_name = left(ls_sname,pos(ls_sname,'先生') -1)
update customer_conf set lianxiren = :ls_name where mingcheng = :ls_str and lianxiren = :ls_sname;
commit;
end if
next
dw_1.retrieve()
string ls_sname,ls_name,ls_str
int i
ll_rowcount = dw_1.rowcount()
for ll_row = 1 to ll_rowcount step +1
ls_sname = dw_1.getitemstring(ll_row, "LIANXIREN")
ls_str = dw_1.getitemstring(ll_row,"MINGCHENG")
if pos(ls_sname,'先生') > 0 then
ls_name = left(ls_sname,pos(ls_sname,'先生') -1)
update customer_conf set lianxiren = :ls_name where mingcheng = :ls_str and lianxiren = :ls_sname;
commit;
end if
next
dw_1.retrieve()
#12
现在好了