Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Substring from a specific word

 
Raj kalaria
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • 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
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic