字符串操作

Joson.e8love 2008-11-17 07:05:33
13,193,116$,2$,3$,134$,100$,195$,204,138$,185$,180$,184,186,191,1

有上边的字符串 怎么得到 不带$的

这样的字符串 13,193,204,184,186,191,1
...全文
147 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Joson.e8love 2008-11-18
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 vrhero 的回复:]
引用 5 楼 e8love 的回复:
The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)

谢谢你的意思 我明白了 但 提示 上述错误 我用 不知道要引入 什么

需要引用泛型命名空间 using System.Collections.Generic;...另外必须.NET 2.0以上...

用2楼的正则表达式...不要用循环...
[/Quote]

谢谢 大家 (*^__^*) 结贴了
Joson.e8love 2008-11-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 Zhanlixin 的回复:]
string strOld = "13,193,116$,2$,3$,134$,100$,195$,204,138$,185$,180$,184,186,191,1";
string strNew=strOld.Replace("$","");
[/Quote]
你没明白我意思 不是 替换$ 是 去掉带$的项
vrhero 2008-11-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 e8love 的回复:]
The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)

谢谢你的意思 我明白了 但 提示 上述错误 我用 不知道要引入 什么
[/Quote]
需要引用泛型命名空间 using System.Collections.Generic;...另外必须.NET 2.0以上...

用2楼的正则表达式...不要用循环...
Zhanlixin 2008-11-18
  • 打赏
  • 举报
回复
string strOld = "13,193,116$,2$,3$,134$,100$,195$,204,138$,185$,180$,184,186,191,1";
string[] strTmp = strOld.Split(',');
string strNew = "";
foreach (string s in strTmp)
{
if (s.IndexOf("$") < 0)
{
strNew = strNew + s + ",";
}
}

strNew = strNew.TrimEnd(',');
Joson.e8love 2008-11-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 min_jie 的回复:]
C# code
string result=System.Text.RegularExpressions.Regex.Replace(str,@"\d+\$,?","");
[/Quote]

非常好的方法 但 我不是很懂 正则 o(∩_∩)o... 哎郁闷 反正问题解决了 嘿嘿
Joson.e8love 2008-11-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 tmxk2002 的回复:]
string txt = "13,193,116$,2$,3$,134$,100$,195$,204,138$,185$,180$,184,186,191,1";
string[] temp = txt.Split(',');
List <string> l = new List();
foreach(string s in temp)
{
if(s.IndexOf("$") < 0)
{
l.Add(s);
}
}

string result = new String(l.ToArray());
[/Quote]

The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)
Joson.e8love 2008-11-18
  • 打赏
  • 举报
回复
The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)

谢谢你的意思 我明白了 但 提示 上述错误 我用 不知道要引入 什么
Zhanlixin 2008-11-18
  • 打赏
  • 举报
回复
string strOld = "13,193,116$,2$,3$,134$,100$,195$,204,138$,185$,180$,184,186,191,1";
string strNew=strOld.Replace("$","");
wangping_li 2008-11-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 min_jie 的回复:]
C# code
string result=System.Text.RegularExpressions.Regex.Replace(str,@"\d+\$,?","");
[/Quote]
这个方法好
止戈而立 2008-11-17
  • 打赏
  • 举报
回复

string result=System.Text.RegularExpressions.Regex.Replace(str,@"\d+\$,?","");
  • 打赏
  • 举报
回复
string txt = "13,193,116$,2$,3$,134$,100$,195$,204,138$,185$,180$,184,186,191,1";
string[] temp = txt.Split(',');
List <string> l = new List();
foreach(string s in temp)
{
if(s.IndexOf("$") < 0)
{
l.Add(s);
}
}

string result = new String(l.ToArray());

62,269

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧