假设我有一个 Java 字符串。
"abcdefghijklmnopqrstuvwxyz0123456789...."
有没有办法找出它可以“适合”多少个选项卡?因此,例如,
如果我打印
"\t\t\t\t\t..."
什么时候制表符的视觉长度会超过字符串?或者换句话说,如何找出制表符空格的长度?
最佳答案
假设您使用标准的 1 个制表符 = 4 个空格。
String myString = "abcdefghijklmnopqrstuvwxyz0123456789....";
//I'm not sure what you want to do with the extra characters,
//Just replace round by floor, or ceil if you'd like...
//If you want to floor, then just do: int nbOfVisualTabs = myString.length()/4
int nbOfVisualTabs = Math.round( (double)myString.length()/4.0 );
关于java - 如何以编程方式找出一个字符串可以容纳多少个 "tabs"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12624679/