简体   繁体   English

正则表达式用 y 轴替换 x 轴(Java)

[英]Regex to replace x axis with y axis (Java)

I have a string with coordinates I want to pass on my.kml file.我有一个带有坐标的字符串,我想将其传递给 my.kml 文件。 But in order for it to work I have to replace the numbers on the x axis with the numbers on the y axis ( photo ).I am working on android studio.但为了让它工作,我必须用 y 轴上的数字(照片)替换 x 轴上的数字。我在 android 工作室工作。 Is there a Regex for this so that I can use the.replace() method?是否有一个正则表达式,以便我可以使用 .replace() 方法?

That's not how regex works.这不是正则表达式的工作方式。 When it comes to string manipulation, simple is best.当涉及到字符串操作时,简单是最好的。 Try something like this:尝试这样的事情:

public static String flipCoords(String input) {
    StringBuilder output = new StringBuilder();
    String[] coords = input.split("\\s");
    for (String coord : coords) {
        String[] point = coord.split(",");
        if (output.length() > 0) {
            output.append(' ');
        }
        output.append(point[1]).append(',').append(point[0]);
    }
    
    return output.toString();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM