You need to sign in to do that
Don't have an account?
mahi68
How to divide the string into for every 70 characters and put at the end -
Hi,
How I can divide the long text into no of lines,
Ex: "hello good morning" just assume r is the 70 character
then I would like to divide like this
hello good mor-
-ning
Any help is Appreciated
Where you want to divide it? inside apex code?
If so, use function subString
'hamburger'.substring(4, 8); // Returns "urge"
no man, i have a string assume 1000 characters.
for each line i would like to display only 70 characters. 1000/70=15 lines
Hello,
I would do something like this:
String input = 'hello good morning';
String tempString = '';
List<String> dividedStrings = new List<String>();
boolean cont = true;
while (cont)
{
tempString = input.substring(0, 70);
dividedStrings.add(tempString);
if (temp1.length() = 70 && input.length() > 70)
input = input.substring(70, input.length());
else
cont = false;
}
At the end you have a list with all your strings separated.
Then loop it.
something like:
Integer currentPos=0;
while(currentPos<myStr.length())
{
String subStr = myStr.subString(currentPos, currentPos + 70);
//do something with subStr....
currentPos+=70;
}
String [] strParse;
If (strInput == null) {
strParse.add '';
} else {
// Add them in 172 character blocks
do {
strParse.add strInput.subString(0, 70);
strInput = strInput.subString(70, strInput.length() - 70);
} while (strInput.length > 70);
strParse.add strInput;
}
you can use substring method..
Heres a document link that gives details about all the strign methods:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_string.htm
Hello,
Try this......
public static void splitString(String strText, Integer noOfChar){
if(strText <> null && strText.length()>noOfChar){
List<String> lstStr = new List<String>();
while(strText.length() > noOfChar){
String strTemp = strText.left(noOfChar);
strText = strText.subString(noOfChar, strText.length());
lstStr.add(strTemp);
}
system.debug('RESULT:>>>');
for(String str:lstStr){
system.debug(str);
}
}
//else no need to split
}
You can use a regular expression to quickly parse the string. Here's the format that separates a string, breaking by spaces:
Removing the " " near the end of the pattern will break it into strings exactly 70 characters long.