• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Formatting a String

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to restrict a particular string to the following format. i.e multiple strings can be concatenated by & operators followed by ! operator. But once the concatenated string has a ! operator in it, no more strings can be used to concatenate using the & operator.
For eg;
A&E!Y!Z!W is allowed
But A&E&Y!Z&W is not allowed.
How can this be achieved ?
Regards
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
As per ur requirement,
Lets say that the concatenated string is conStr ,
We need to check for the existence of "!" before appending the newly entered string,
we can check for the existence of "!" using indexOf method ,
conStr.indexOf("!"), this returns an ineteger,
if thios integer is greater than -1 , then it represents that the character already exists,
and then u dont concatenate the new entered string.
otherwise "!" is not present in conStr, and then u can concatenate
hope this solves ur problem
njoy coding
keerthi
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sandy,
Welcome to the JavaRanch! Please adjust your display name to meet
the JavaRanch Naming Policy. You can change it here.
Thanks!
and welcome to the JavaRanch!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic