简体   繁体   English

如何在字符串中找到全角字符的索引?

[英]How to find index of fullwidth character in String?

I wrote a function to find a space (in full-width) in a String .我编写了一个函数来在String查找空格(全角)。 But indexOf cant find it and returns -1 .但是indexOf找不到它并返回-1 This is my function:这是我的功能:

public static String getflagCheck(String content) {

    List<String> supplierNames = Arrays.asList("//");
    String remark = "x";

    boolean flagValid = false;
    for (int i = 0; i < supplierNames.size(); i++) {
        int index =  content.indexOf(supplierNames.get(i));
        int indexTestPoint = content.indexOf(" ");
        System.out.println(index);
        System.out.print(indexTestPoint + "\n\n");
        if(index > -1) {
                flagValid = true;
                if(indexTestPoint < index) {
                    flagValid = false;
                }
            break;
        } 
    }
    if(flagValid) {
        remark = "x";
    } else {
        remark = "needcheck";
    }
    return remark;
}

Your "space" at你的“空间”在

int indexTestPoint = content.indexOf(" ");

Isn't a space character but is a tab character.不是空格字符而是制表符。 Replace it with a space.用空格替换它。

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

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