Posts

Showing posts with the label Whitespace

All The Whitespace Characters? Is It Language Independent?

Answer : Whether a particular character is categorized as a whitespace character or not should depend on the character set being used. That said, it is not impossible that a programming language can make its own definition of what constitutes whitespace. Most modern languages use the Unicode Character set, which does have a definition for space separator characters . Any character in the Zs category is a space separator . You can see the complete list here. In addition you can grep for ;Zs; in the official Unicode Character Database to see those characters. Note that the number of characters in this category may grow as new Unicode versions come into existence, so I will not say how many such characters exist, nor even attempt to list them. In addition to the Zs Unicode category , Unicode also defines character properties . Among the properties defined by Unicode is a Whitespace property. As of Unicode 7.0, characters with this property include all of the characters wi...

Adding Whitespace In Java

Answer : I think you are talking about padding strings with spaces. One way to do this is with string format codes. For example, if you want to pad a string to a certain length with spaces, use something like this: String padded = String.format("%-20s", str); In a formatter, % introduces a format sequence. The - means that the string will be left-justified (spaces will be added on the right of the string). The 20 means the resulting string will be 20 characters long. The s is the character string format code, and ends the format sequence. There's a few approaches for this: Create a char array then use Arrays.fill, and finally convert to a String Iterate through a loop adding a space each time Use String.format