on 10-10-2008 4:32 AM
Hi,
I have a string like title-name.
i want to capture only title into another string.
how can i do it. kindly suggest.
Hi Prasanthi
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<i>);
}
wdComponentAPI.getMessageManager().reportSuccess("----
");
}
}
Thanks
Anup
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi just impliment this code
String text = "title-name"
String[] words=text.split("-"); // this splits at delimiter.
String title = words[0];
//then in title string you can capture your titlename
Regards
Raghu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi prasanthi,
Use the folllowing code
String s1 = "abc-def-ghi-jkl";
String []s2 = s1.split(String regex);
Your regex contains the "-" string.
You can get any value from s2 by giving the index number.
Hope this will help you.
Regards
Sagar Ingalwar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what should i do to capture the string till the first occurance of
"-".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi reddy,
If you have string "title-name" stored in AC ,you can split the string in following way,
int in = AC.indexOf("-");
String AC1 = AC.substring(0,in);
Hope this will help;
Regards,
Prajakta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
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.