Hi!

I would like to change the string: "reg_num, reg_date, attached_file, Description" to the new string: "reg_num, reg_date, Description, attached_file" .

So, what I need is to search the substring "attached_file" and put in at the end of the main string. How could I do that? Thanks!

I solved the problem as follows, but maybe someone knows more elegant way?

private static String swapper(String str) {
        String attFile = new String(", attached_file");
        int start = str.indexOf(", attached_file");
        String attachedFile = str.substring(start, start + attFile.length());
        String strNew = str.replace(attachedFile, "");
        String strFin = strNew.concat(attachedFile);
        return strFin;
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.