Because I'm generating strings that require inserting and appending
words, I keep sticking in little pieces of code to make sure the
white space is correct. Thus I propose two versions of a utility
function that would do this and check the white space (see below).
The first version will append the word to the end (could call it
append word). The second will insert it at the specified position.
Any thoughts?
Jonathan
String insertWord(String oldstr, String word){
if (oldstr.length() > 0 && !oldstr.endsWith(" "))
oldstr += " ";
oldstr+=word;
return oldstr;
}
String insertWord(String oldstr, String word, int insertpt){
if (oldstr.length() == 0) {
oldstr = word;
return oldstr;
}
String part1 = oldstr.substring(0, insertpt);//may have my indexes
messed up...need to check
String part2 = oldstr.substring((insertpt+1),oldstr.length());
if (!part1.endsWith(" "))
part1 += " ";
if (!part2.beginsWith(" "))
part2 = " "+part2;
part1+=word;
oldstr = part1 + part2
return oldstr;
}
Dr. Jonathan H. Gutow
Chemistry Department [email protected]
UW-Oshkosh Office:920-424-1326
800 Algoma Boulevard FAX:920-424-2042
Oshkosh, WI 54901
http://www.uwosh.edu/faculty_staff/gutow/
------------------------------------------------------------------------------
_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers