• 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

Substring from a specific word

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi


I hava a string sql

sql = select object_name, tilte, subject from dm_document where

Now if i want a susbstring say

newsql = object_name, tilte, subject

how can i acheive this

sql.substring( ) ???

pla help
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, but I'm not understanding what you need to do. Can you provide more detail on your critera for creating the substring?
 
Raj kalaria
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeh

see i have a string

string abc = "select object_name, tilte, subject from dm_document where"


Now i want a susbstring from abc containing "object_name, tilte, subject"
that is
newabc = "object_name, tilte, subject"

how can i achieve this
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
StringTokenizer or String.split() will split a string on some delimiter. You could replaceAll() commas with spaces and use a space delimiter to process the words one at a time:

Try that and see how it works. Then we can talk about regular expressions. If you don't know them they are significantly trickier and could "capture" all the text between "select" and "from" and probably even capture one word at a time.
 
Raj kalaria
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi james

thanks for yr input i will defi try that

but for time bieng i did as follow
--------------****************---------------------------
int pos = str.indexOf( "select");
int pos1 = str.indexOf( "from");
String str1 = str.substring(6,pos1);

---------------************--------------------

but i am not happy with the logic .

I will look to yr logic thanks a lot

Raj
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic