我在表格中有一列,有些值反斜杠/朝向结尾。我想删除这些斜杠值并保留其余的文本。所以我要说我有一个文字"myjunkdata/"
,它应该给我回复"myjunkdata"
。但是以下条件不起作用。
(StringHandling.RIGHT(row1.CertificateName,1) == "/") ? StringHandling.LEFT(row1.CertificateName,StringHandling.LEN(row1.CertificateName)-1) : row1.CertificateName
以下示例数据
Certified SOA Security Specialist/
Information Security Management Principles Foundation Certificate/
Check Point Certified Security Administrator R77/
Check Point Certified Security Expert R77/
Check Point Managed Security Expert/
Cisco Certified Network Associate Security
Cisco Certified Network Professional Security
Cisco Certified Internetwork Expert Security
Cisco Certified Network Professional Security
有人可以帮忙吗?
答案 0 :(得分:3)
不要将String
与==
StringHandling.RIGHT(row1.CertificateName,1).equals("/")
但你可以用以下方式做同样的情况:
row1.CertificateName.endsWith("/")
但是,当然,正则表达式始终是一个简单的解决方案
row1.CertificateName.replaceAll("/$")
正则表达式/$
基本上意味着以/
结尾,因此如果该字符存在,它将删除该字符。