You need to sign in to do that
Don't have an account?
nbansal10
Split long account name
Hi there
Would like to know if anyone has encountered this? If some account's name is over 50 characters long, we would like to capture as much the first 50 characters but complete words in Name, and then the splii over to Name2. We would not want to split a word in half.
Any suggestions would be great.
Thanks!
Would like to know if anyone has encountered this? If some account's name is over 50 characters long, we would like to capture as much the first 50 characters but complete words in Name, and then the splii over to Name2. We would not want to split a word in half.
Any suggestions would be great.
Thanks!
if(name.length() >= 50)
{
string name2 = name.substring(0,50);
}
string name=name;
//Initialize name1 to equal name.
String name1 = name;
String name2;
//If name is less than 50 characters, then we don't have to do anything
if (name.length() >= 50) {
//This is the first 50 characters
name1 = name.substring(0, 50);
//This is the rest of the name
name2 = name.substring(50, name.length());
//If name2 starts with a space, then we have already split it between words, so we're done
if (!name2.substring(0, 1) == ' ') {
//Get the index of the last occurrence of the space character in name1
Integer lastSpaceIndex = name1.lastIndexOf(' ');
if (lastSpaceIndex != -1) {
//Take everything after the last space in name1 and prepend it to name2
name2 = name1.substring(lastSpaceIndex, name1.length()) + name2;
//Now remove everything after the last space in name1
name1 = name1.substring(0, lastSpaceIndex);
}
}
}