替换每个出现的角色,但最后 [英] Replace every character occurence but last

查看:77
本文介绍了替换每个出现的角色,但最后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一串 a.b.c.d 。如何编写将该字符串转换为 abc.d 的方法?或者有没有任何可用的方法实现?

Lets say I have a string of a.b.c.d. How do I write a method which will transform that string into abc.d ? Or is there any method available implementation out there ?

到目前为止我尝试了什么

What I have tried so far

        int dotPlacing = propertyName.lastIndexOf(".");//12
        String modString = propertyName.replace(".", "");
        modString = modString.substring(0, dotPlacing-1) + "."+modString.substring(dotPlacing-1);

我正在使用它来编写Hibernate标准。它适用于 user.country.name ,但不适用于 user.country.name.ss 。没有尝试过任何其他字符串。

I am using that for writing Hibernate criteria. It works for user.country.name but not for user.country.name.ss. Havent tried for any other strings.

推荐答案

你可以将子字符串形式0提取到 lastIndefOf('。' )。在此子字符串中,将所有替换为空字符串。与子串合并后(从 lastIndexOf。到结束)

YOu can extract substring form 0 to lastIndefOf('.'). In this substring replace all . to empty string. After that merge with subtring (from lastIndexOf . to end)

这篇关于替换每个出现的角色,但最后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆