I am using method startsWith to find out, whether my string starts with desired string. Example:

       for(int i=0;i<tokens.length;i++){
           if(tokens[i].startsWith(ColumnName)){
                tokens[i]="";

           }

In tokens[i] there is a string "info REAL", in ColumnName, there is a string "info". In this comparsion, every time i get false. It is unbelivable, but even when i print it, it is like - tokens[i]:info REAL, startsWith:info, result:false...

I don't see any mistake here, you do? There is no TYPO in my program, I am 100% sure theese values are here correctly.

Thanks

有帮助吗?

解决方案

check for spaces in the strings, its easy to overlook them in the console output.

e.g. "info REAL" vs "info " or "info REAL" vs " info"

其他提示

Maybe it's caused by whitespaces. Have you tried trimming your strings before doing that ?

Something like tokens[i].trim().startsWith(ColumnName.trim())

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top