• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

characters and numbers seperation in a string

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having string like "65234Markets6713Investments".

I need to seperate this string as 65234,Markets,6713,Investments.


I have used the logic like :



But i am able to get the ouput like 65234,Markets6713,Investments.

can any one help me out in this.


 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Praveen, you might wanna try this....

public static void main(String[] args) {
String s = "65234Markets6713Investments";
StringBuffer sb = new StringBuffer();
int pos = 1;
char[] ch = s.toCharArray();
for (int i = 0; i < ch.length; i++) {

if (Character.isDigit(ch[i])) {
if(pos!=1)
{
pos=1;
sb.append(',');
}
sb.append(ch[i]);

} else {
if (pos == 1) {
sb.append(',');
}
sb.append(ch[i]);
pos++;
}
}
System.out.println(sb.toString());
}




This gives this result

65234,Markets,6713,Investments



Nek
 
praveen oruganti
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes now it's working.

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try this


 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If we're going to throw around solutions, here's mine:
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its really beautiful Rob,
 
Rob Spoor
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course it is
But thanks for the compliment.
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since no one has posted the obligatory cryptic regex solution, I guess I'll provide one:

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to write the following condition can someone help me

1. the string should be like the following
You may use letters, numbers, underscores, and one dot (.) , i think with regular expressions we can do it.

2. one more string should be in the below format.
Use 6 to 32 characters, no spaces.

please somebody help me. this validation i am doing in serverside.




 
Marshal
Posts: 80639
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't add a new question to somebody else's thread. That question probably merits a thread of its own, with a link to this thread if the patterns are similar.
 
reply
    Bookmark Topic Watch Topic
  • New Topic