on 10-27-2008 10:04 AM
Hi All,
I have a string with maximum no of characters as 100,
I want to split this string into 4 equal parts.
Any help will be appreciated.
Regards
Hi,
Hope the following Threads will help you regarding your problem.
Similar thread from SDN may help you out.
https://forums.sdn.sap.com/click.jspa?searchID=17937952&messageID=6342839
Thanks.
Nitesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rajeev,
Use this sample code
class SplitString {
public static void main(String[] arguments) {
StringTokenizer ex1, ex2; // Declare StringTokenizer Objects
int count = 0;
String strOne = "one two three four five";
ex1 = new StringTokenizer(strOne); //Split on Space (default)
while (ex1.hasMoreTokens()) {
count++;
wdComponentAPI.getMessageManager().reportSuccess("Token " + count + " is" + ex1.nextToken() );
}
count = 0; // Reset counter
String strTwo = "item one,item two,item three,item four"; // Comma Separated
ex2 = new StringTokenizer(strTwo, ","); //Split on comma
while (ex2.hasMoreTokens()) {
count++;
wdComponentAPI.getMessageManager().reportSuccess("Token " + count + " is "+ ex2.nextToken() );
}
}
}
Thanks
Anup
Edited by: Anup Bharti on Oct 27, 2008 12:36 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Following is a sample code may be of use for you....
String string = "abcdefgh";
int length = string.length();
int splitLength = length / 4;
int beginIndex = 0;
int endIndex = splitLength;
for(int x=0; x<4; x++)
{
String str = string.substring( beginIndex, endIndex);
beginIndex = endIndex;
endIndex = endIndex + splitLength;
System.out.println(str);
}
Regards
Ayyappraj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.