Users Pricing

forum

Home Forums Replacement of English numbers of a string with Roman numbers using java – MindStick

Replacement of English numbers of a string with Roman numbers using java

Anonymous User 2116 14 Oct 2013

I'm going to find number chars in  a String and replace them with their Roman versions. The Code is:

public static void main(String[] args) {

    String pattern = "[0-9]+";
    Pattern p = Pattern.compile(pattern);
    String mainText = "34titi685dytti5685fjjfj8585443";
    Matcher m = p.matcher(mainText);
    int i = 0;
    while (m.find()) {
        System.out.println("Match number " + i);
        String tmp = m.group();
        char[] cTmp = tmp.toCharArray();
        for (int j = 0; j < cTmp.length; j++) {
            cTmp[j] = (char) ((int) cTmp[j] + 1584);
        }
        m.group().replaceFirst(tmp,new String(cTmp));
        i++;
    }
    System.out.println(mainText);
}


But at the end it prints the same string main text. What is wrong with my code?


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md