How do i use split or stringtokenizer to get only the 1st character of each word to create an acronym? It would also include the ‘&’ symbol. And it isn’t case sensitive
exmaple:
- Some Kind Of Long String —> SKOLS
- another Kind of Long String —> AKOLS
- string & string —> s&s
The reason for this is because i have a query that populates a table, and since the column name are 3 or more words each. it stretches the table, even with a scroll bar placed, 100+ columns with long names would make it look really long. So i would like to reduce space by using only acronyms and generating a legend.
First you need to split the
Stringat either ” ” or “&”.You can use the “split” method for String. http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)
The regular expression would be either space or ampersand.
Then you would use the
charAtmethod to get the character at index 0. You would concatenate the characters to get the acronym.