• 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

Looking for simple pattern/algorithm to parse text with tokens

 
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all
i have several tamplets text in this tamplets text i have tokens that represent some actions
i need to do ( usually replace it with different string ) when i process the text in my application
the actions i need to do based on the tokens in the string will be activate from different sources
for example if token called @_db_name_@ will be found in the application i will know
i need to replace it with name coming out from the DB , and if i will find the token @_calc_id_@
in the application i will know i need to calculate the id of the object based on X and Y
im looking for common pattern or algorithm that will help me to do it more generic .
Thanks allot
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Meir,

usually it's the most efficient way to do this with regular expressions. If you're absolutely not familiar with regular expression it may seem difficult and strange at first but it's worth the effort of learning. Have a look at the corresponding Sun tutorial. Regular expressions let you find such patterns and simply replace the text or invoke some action.

Marco
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also take a look at the Command or Strategy pattern.
reply
    Bookmark Topic Watch Topic
  • New Topic