简体   繁体   English

如何从字符串中删除第一个特殊字符

[英]how to remove first special character from string

I have values seperated by pipes in a database. 我在数据库中用管道将值分开。 But the issue is that I am appending | 但是问题是我要附加| at every entry. 在每个条目。

For Example: 例如:

|275634|374645|24354| | 275634 | 374645 | 24354 |

How can I remove the first pipe from the whole string not all the pipes. 如何从整个字符串而不是所有管道中删除第一个管道。

Once inserted I don't need to check for the next time when it updates. 插入后,下次更新时无需检查。

If I use substring(1) then it will remove the first character every time, 如果我使用substring(1),它将每次删除第一个字符,

Please suggest a fix? 请提出解决方案?

//input = '|275634|374645|24354|';
output = input.replace('|', '');

String#replace will replace the first occurance in a String. String#replace将替换字符串中的第一个匹配项。 If you replace it with an empty String '' it is removed. 如果用空字符串''替换它,则将其删除。

jsFiddle 的jsfiddle

you can use substring(index) method where ever you want to remove the perticular special character from the String: like 您可以在想要从字符串中删除垂直特殊字符的地方使用substring(index)方法:

String str2 = "|275634|374645|24354|";
 str2 = str2.substring(1);
System.out.println(str2);

you can see the output as 275634|374645|24354| 您可以看到输出为275634|374645|24354|

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM