删除嵌入字符串(Delete embedded string)
我正在寻找能够让我“删除嵌入字符串”的最有效的Java方法。 例如,如果我有字符串"Bob said \"Hello world!\"." ,我打电话给它的方法,结果应该是: "Bob said ." 。 帮助将不胜感激!
请注意,我希望这种方法是通用的 ,所以如果Bob说“hello world”之外的东西,它仍然可以工作。
I'm looking for the most efficient Java method that would allow me to 'delete an embedded string'. For example, if i had the string "Bob said \"Hello world!\".", and I call the method on it, the result should be: "Bob said .". Help would be appreciated!
Note that I want this method to be general, so that if Bob says something besides "hello world" it would still work.
最满意答案
你可以试试
String string = "Bob said \"Hello world!\"."; string = string.replaceAll("\"[^\"]+\"", "");如果您只想删除第一个引用的文本,请使用replaceFirst。
You can try
String string = "Bob said \"Hello world!\"."; string = string.replaceAll("\"[^\"]+\"", "");Use replaceFirst if you only want to remove the first quoted text.
更多推荐
发布评论