Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

extracting string

 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,

I need your advise in one case that i am scanning a card , it may be any card but if it contains any number begging with 'LYL' then it should be treated specially, rest all we ignored , so what logic we have that we scan all the cards and check that whether it is begging with 'LYL' series , if yes then e will treat them specially rest we ignored...

complete card format would be LYL01016278572011000000012




Is there any other way in java to achieve this..! through regular expressions or through regex pattern ...!! please advise..!!


 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What you are trying to achieve can easily be done with startsWith method of String class.
 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anayonkar Shivalkar wrote:Hi,

What you are trying to achieve can easily be done with startsWith method of String class.


Hi ,

Thanks a lot, could you please also show me how the above code can be converted with startsWth() that will be a great help..!! thanks a lot..!!
 
Manoj Kumar Jain
Ranch Hand
Posts: 198
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at the startsWith method in String class, there is nothing much to use this method in the above code..
Method name itself suggest what it does...Just put it in if condition..
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This appears to be at least the third thread in a series. Time for you to give the String and Pattern API a thorough read.
http://www.coderanch.com/t/572056/java/java/extracting-portion-number-string
http://www.coderanch.com/t/572089/java/java/masked-String
 
Henry Wong
author
Marshal
Pie
Posts: 21506
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:This appears to be at least the third thread in a series. Time for you to give the String and Pattern API a thorough read.
http://www.coderanch.com/t/572056/java/java/extracting-portion-number-string
http://www.coderanch.com/t/572089/java/java/masked-String



Agreed. Regular expressions is not something that can be learned from a forum. If you are going to insist to use it, as a learning exercise, in place of simpler options, then we recommend actually picking up a tutorial / book.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic