my dog learned polymorphism*
The moose likes Java in General and the fly likes Substring from a specific word Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Substring from a specific word" Watch "Substring from a specific word" New topic

Substring from a specific word

Raj kalaria
Ranch Hand

Joined: Sep 08, 2005
Posts: 72

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

Joined: Aug 31, 2004
Posts: 11343

Sorry, but I'm not understanding what you need to do. Can you provide more detail on your critera for creating the substring?

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Raj kalaria
Ranch Hand

Joined: Sep 08, 2005
Posts: 72

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

Joined: Jan 29, 2003
Posts: 8791
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.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Raj kalaria
Ranch Hand

Joined: Sep 08, 2005
Posts: 72
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

wood burning stoves
subject: Substring from a specific word
Similar Threads
Loadjava and user_objects table
view ddl for all triggers
Show images on the screen without using JFrame
Different restults from Oracle and JDBC
Handling Null Values In Jdbc