Solved Replacing one or more '_' with different strings

Discussion in 'Plugin Development' started by kreashenz, Aug 21, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    kreashenz

    I'm trying to get a way to replace all the '_' with different strings. If you don't understand what I mean; change "_, my name is _." to "Hello, my name is kreashenz."

    I've been trying to work this out as there's no (afaik) method to do this.
     
  2. Code:
    String[] splitted = "_, my name is _.".split(Pattern.quote("_"));
    String[] words = new String[]{"Hello ", "Shmobi"};
    String str = "";
    for(int i = 0; i < words.length; i++){
    str = str + words[i]+splitted[i];
    }
    kreashenz is that what you mean?
     
  3. Offline

    _LB

    Code:java
    1. String result = String.format("%1$s, my name is %2$s", "Bob", "Alice");
    No need to reinvent code that already exists and works better.
     
    kreashenz likes this.
  4. Offline

    kreashenz

    Thanks both of you. I completely forgot about _LB's way, and I managed to make a simple method to do what I needed.
     
Thread Status:
Not open for further replies.

Share This Page