diff --git a/CS2JLibrary/src/CS2JNet/System/StringSupport.java b/CS2JLibrary/src/CS2JNet/System/StringSupport.java index 94bcb6f..92e8fa2 100755 --- a/CS2JLibrary/src/CS2JNet/System/StringSupport.java +++ b/CS2JLibrary/src/CS2JNet/System/StringSupport.java @@ -24,6 +24,8 @@ package CS2JNet.System; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class StringSupport { @@ -365,7 +367,17 @@ public class StringSupport { // Takes a C# format string and converts it to a Java format string public static String CSFmtStrToJFmtStr(String fmt) { - return fmt.replaceAll("\\{(\\d)+\\}", "%$1\\$s"); + Pattern p = Pattern.compile("\\{(\\d)+\\}"); + Matcher m = p.matcher(fmt); + StringBuffer sb = new StringBuffer(); + while (m.find()) { + // In C# positions are indexed from 0, in Java they are indexed from 1 + // so "{0} = {1}" -> "%1$s = %2$s" + String replacement = "%" + String.valueOf(Integer.parseInt(m.group(1)) + 1) + "\\$s"; + m.appendReplacement(sb, replacement); + } + m.appendTail(sb); + return sb.toString(); }