cancel
Showing results for 
Search instead for 
Did you mean: 

How to split the string

Former Member
0 Kudos

Hi Experts,

I have a string with maximum no of characters as 200,

I want to split this string into two parts with 100 100 characters,

How to do that?

I tried using split() function but i dont how to use it when splitting with no of characters.

Regards

Upendra

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

if String s="sub string";

String s1=s.substring(0,3);

String s2 =s.substring(4,9);

use the above code to split the string s into "sub" and "string".

Regards,

ramesh

Edited by: Ramesh Babu V on Oct 13, 2008 12:52 PM

Answers (2)

Answers (2)

former_member192434
Active Contributor
0 Kudos

Hi upendra,

You can either of the following code, for spliting and capturing the string.

1.

StringTokenizer st = new StringTokenizer("this is a test");

while (st.hasMoreTokens()) {

wdComponentAPI.getMessageManager().reportSuccess(st.nextToken());

}

2.

class StringSplit {

public static void main(String args[]) throws Exception{

new StringSplit().doit();

}

public void doit() {

String s3 = "Real-How-To";

String [] temp = null;

temp = s3.split("-");

dump(temp);

}

public void dump(String []s) {

wdComponentAPI.getMessageManager().reportSuccess("----


");

for (int i = 0 ; i < s.length ; i++) {

wdComponentAPI.getMessageManager().reportSuccess(s);

}

wdComponentAPI.getMessageManager().reportSuccess("----


");

}

}

Thanks

Anup

Former Member
0 Kudos

hi!

you can take two string where you can store the splitted string.

String s1 = str.substring(0, 99);

String s2 = str.substring(100, 199);

thanks

vishal