Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Formatting a String  RSS feed

 
sandy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
 
keerthi matta
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!