小编Pol*_*ear的帖子

Replacing some but not all occurrences of a char in Java String

I am learning Java, and in a task I have to replace some but not all occurrences of a '-' to a '(' and same for '*' a ')', only if the inside of the - is an id as as follows:

String input = "-id1234* -id1235* -id1236* Do not replace these -signs*";
String output = "(id1234) (id1235) (id1236) Do not replace these -signs*";
Run Code Online (Sandbox Code Playgroud)

I have tried iterating through a loop, and replacing the first occurrence once the for loop …

java string char

1
推荐指数
1
解决办法
307
查看次数

标签 统计

char ×1

java ×1

string ×1