Subject: extract the string before space

I have a string say "aquarium a". i want to extract the string appearing before the space and discard the string appearing after space.
that is the resultant string required is "aquarium". any number of characters can appear after space.
is it possible to solve using replace() method. i cant hardcode space+character in replace method because number of characters after space is not known.
Is there any easy way to get the required result

> i want to check if a string has space in between then
only this code should run otherwise this code should
not run. because if a string doesn't have any space
inbetween then the above code will give error.
String s = "aquarium a";
s = s.split("\\s")[0];
assert s.equals("aquarium");At this point, it would be a good idea to familiarize yourself with the String API. That way, you'll have a better idea how to accomplish your specific requirements.
~

Similar Messages

  • Oracle Text Index  - Trailing Search when the String has spaces

    Hi Am trying to use CONTAINS to tune a trailing LIKE search.  But it's not working when the string has spaces in between them
    For e.g in say if table person has column name which has following values
    JOHN
    FRED JOHNSON
    JOHN ROBERTS
    select * from person where name like 'JOHN%'
    Above query will give JOHN and JOHN ROBERTS. If i use CONTAINS As below
    select * from person where CONTAINS(name,'JOHN%',1) > 0
    It brings back all three records. If i remove spaces in column itself, its working bit if i try to remove spaces in Query, i am getting a Text error as i have Text index only on the name column.  I would like to know is it possible to use CONTAINS but get same result set on trailing search as how a normal LIKE will do.
    Below is how i did Index creation
    create index txt_idx1 on person (name)
    indextype is ctxsys.context
    parameters('DATASTORE ctxsys.default_datastore');

    You could use some method, like a multi_column_datastore or user_datastore to append some specific starting characters, then include those in your search, as shown below.
    SCOTT@orcl12c> CREATE TABLE person
      2    (name  VARCHAR2(60))
      3  /
    Table created.
    SCOTT@orcl12c> INSERT ALL
      2  INTO person VALUES ('JOHN')
      3  INTO person VALUES ('FRED JOHNSON')
      4  INTO person VALUES ('JOHN ROBERTS')
      5  SELECT * FROM DUAL
      6  /
    3 rows created.
    SCOTT@orcl12c> BEGIN
      2    CTX_DDL.CREATE_PREFERENCE ('test_ds', 'MULTI_COLUMN_DATASTORE');
      3    CTX_DDL.SET_ATTRIBUTE ('test_ds', 'COLUMNS', '''start ''||name||'' end'' name');
      4  END;
      5  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl12c> create index txt_idx1 on person (name)
      2  indextype is ctxsys.context
      3  parameters('DATASTORE test_ds')
      4  /
    Index created.
    SCOTT@orcl12c> select * from person where CONTAINS(name,'start JOHN%',1) > 0
      2  /
    NAME
    JOHN
    JOHN ROBERTS
    2 rows selected.
    SCOTT@orcl12c>

  • How to extract the string part by part

    I have a variable like,
    var := 'c001','c002','c003';
    I want to take c001 c002 and c003 seperately and insert into some table having one column as seperate rows,
    Please let me know how to do that.
    Thnx for ur response.

    Hi
    Are you using any formula to get count ?  if so, you can convert that in text by using
    If count = 1 then totext(count,"0,000")  // to get thousand separator
    If count = then totext(count,"####") to display without thousand separator without dicimal places.
    Now you use this formula in your chart to avoide dicimal places.
    Thanks,
    Sastry

  • ' character in the string

    Hello.
    I'm trying to insert string to varchar value in the database which contains the ' character. But it throws the error....
    how can i replace this character to some another character in the string before inserting it to the database?
    thanks

    public String replace(char oldChar,
    char newChar)Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
    Fred

  • Verify special char is in String before append into StringBuffer

    I have following code to verify A special char "X" is in the String before continue adding it to a StringBuffer:
    private boolean veriChar(String poem){
    if(peom.indexOf("X")==-1) return false;// make sure X is in the String
    return true
    However, if I only want a single X in String to return true, any method to use? for example: poem=" EXTRA TEXT" (2 Xes here) needs to be rejected to be false.

    take this code compile it and see for yourself.
    public class Test{
      public static void main(String args[]){
        Test t = new Test();
        System.out.println(""+t.veriChar("MATT"));
        System.out.println(""+t.veriChar("MAX"));
        System.out.println(""+t.veriChar("MAXX"));
      private boolean veriChar(String toCheck){
        return!((toCheck.indexOf("X")<0)||(toCheck.indexOf("X")!=toCheck.lastIndexOf("X")));
    } you will see that the first and third ones return false and the second returns true which is as you want.
    now an explanation of what is happening.
    the method looks like this
    private boolean veriChar(String toCheck){
        return!((toCheck.indexOf("X")<0)||(toCheck.indexOf("X")!=toCheck.lastIndexOf("X")));
      }first we check if the special X or whatever exists in the string at all
    toCheck.indexOf("X")<0;this returns true for the first test of MATT
    now we check if the last occurance in our string of the special X is the same position as the first occurance. if it is then we have only one special X. if not then we have more than one special X.
    toCheck.indexOf("X")!=toCheck.lastIndexOf("X")note that we check for not equals so that for MAX it returns false and for MAXX it returns true
    so now we have our answers but they are inverted from what we want so we put the ! which gives the boolean opposite. so that the MAX returns true and the other two return false.

  • Replace string by space

    I would like to replace all ',' appear in a strng by space. So, i use
    replace all occurrences of ',' in tempStr with space.
    But, the outcome is all pattern are replaced, and concatenate together. For example, i have string
    tempStr = '1,2,3,4,5,6,7'
    But the result is
    tempStr = 1234567
    How can i replace the string by space. thanks!

    Hi,
    Try this.
    data : tempstr type string,
    temp(2) type c.
    tempStr = '1,2,3,4,5,6,7'
    temp = ', '.
    Translate tempstr using temp.
    Write tempstr.
    Regards,
    Mohaiyuddin

  • Email: extracting subject line as string

    Is it possible to extract the subject line of an email as a string?
    If so, how might one do that?
    Thanks

    I don't believe this is feasible with the standard output program, but you should be able to do this if you create a custom (Z) version and make that modification there. Not sure if it's worth it, but that's for your business users to decide.

  • Get the string until first space

    hi,
    can anyone provide an example how to get the string until the first space?
    i mean if the value is :
    this is an example
    how to get only the word "this" (before the very first space) by select?
    thanks in advance,

    There are several methods to achieve this:
    SELECT SUBSTR(t.col1, 1, INSTR(t.col1 || ' ', ' ') - 1)
      FROM (SELECT 'this is an example' col1
              FROM dual) t
         ;     or in 10g using regular expressions:
    SELECT REGEXP_SUBSTR(t.col1, '^[^ ]+')
      FROM (SELECT 'this is an example' col1
              FROM dual) t
         ;     C.

  • To extract the last word in a string

    Hi
    I am using BODS 14.1.1.210 
    I would like to extract the last word in a string in BODS query. How can I achieve this when  I don't know how many words are present in a space delimited string.
    Example
    Input                                              Output    
    My name is Tim                              Tim
    Complicated                                    Complicated
    there is a bird in the nest                 nest
    Please let me know if there is a query function for this one.
    Cheers!

    Hi,
    try this-
    word_ext(fieldname,-1,' ')
    Atun

  • Started a similar string before.  When I select a recipient in Messages on my Macbook Pro the name shows up in red and says the recipient is no longer registered on iMessage.  I know that they are registered.  Is there a problem with Contacts?

    Started a similar string before.  When I select a recipient in Messages on my Macbook Pro the name shows up in red and says the recipient is no longer registered on iMessage.  I know that they are registered.  Is there a problem with Contacts possibly.  The previous help has been appreciated but the problem persists.

    Hi,
    Try iMessaging your own iPhone and see if your account is actually logged in.
    It can appear "enabled" and On line but sometimes it is not.
    Also try sending from your iPhone (number) to your Apple ID and see if it gets to the Mac.
    If it does not use the Sign Out button.
    Then shut down the Mac
    On restart add back the Apple ID to the iMessages account settings.
    I also just checked My wife's iPhone as she popped up red.
    It turned out her iPhone did not have Messages On.
    10:00 pm      Tuesday; January 28, 2014
      iMac 2.5Ghz 5i 2011 (Mavericks 10.9)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad

  • How to extract the Datetime from string?

    Hello FOlks,
    I have the sample data whichi is a string and it contains DateTime part inside it. I worked through half way but am not sure how to get the other part.
    The sample data is
    Note Added by AARON HILTON at 05/26/2010 14:53 MONEY NOTE ENTERED
    Note Added by DEBBIE BILL at 11/16/2009 23:12 MONEY ENTERED
    I tried using
    substr(d.assignee_note, INSTR(d.assignee_note,'at')+2,length(d.assignee_note))  but it did not have the desired results.
    How to just extract the datetime part i.e. 11/16/2009 23:12

    If your sample data is representative for all the data, you could also try a regular expression:
    SQL> -- generating sample data, pretending it's stored in a column called str in a table called t:
    SQL> with t as (
      2  select 'Note Added by AARON HILTON at 05/26/2010 14:53 MONEY NOTE ENTERED' str from dual union
      3  select 'Note Added by DEBBIE BILL at 11/16/2009 23:12 MONEY ENTERED' from dual
      4  )
      5  --
      6  -- actual query:
      7  --
      8  select trim(regexp_replace(str, '[[:alpha:]]')) str
      9  ,      to_date(trim(regexp_replace(str, '[[:alpha:]]')), 'mm-dd-yyyy hh24:mi') dt
    10  ,      to_timestamp(trim(regexp_replace(str, '[[:alpha:]]')), 'mm-dd-yyyy hh24:mi') ts
    11  from   t;
    STR                DT                        TS
    05/26/2010 14:53   26-05-2010 14:53:00       26-05-10 14:53:00.000000000
    11/16/2009 23:12   16-11-2009 23:12:00       16-11-09 23:12:00.000000000
    2 rows selected.where column STR is, well, a string, DT will turn your string into date datatype and TS will turn it into a timestamp.
    It isn't clear how you want to extract the datetime part, but it really matters...

  • In the NI Library VI: Extract Numbers, the string control is automatically loaded each time the VI is opened with "Counting to five: one 2 three 4.0 five. Where is this string data coming from?

    Even after deleting the string "Counting to five: one 2 three 4. five." from the string control and replacing it with another string the original string returns after the VI is saved then reopened. Where is this string data coming from? I've attached a copy of the library function. I've been able in my application to get around the problem by replacing the string control with a string constant. But I'm still curious as to what's going on.
    Thanks,
    Chuck
    Solved!
    Go to Solution.
    Attachments:
    Extract Numbers Test.vi ‏9 KB

    Chuck,
    String control has been set to default with the string you are seeing.  To change this, enter the new string, right click the control and select
    Data Operations>>Make Current Value Default
    Now save your vi.

  • Extract the numbers in string using regex

    Hi,
    How to extract the numers in string using regex?.
    Already i tried split up the string using [\\s]
    For ex: "Uting Tatk and Window Panet 15"
    it gives the ans 15.
    if the string is
    For ex: "Uting Tatk and Window Panet 15 New!"
    i can't find the number.
    so plz give me some idea to get the number frm String.
    Thanks

    I am developing a java project to extract Table of
    content in a particular
    PDF.
    i extracted all topics.
    then i want 2 extract page number from dat extracted
    TOC.
    if the TOC ends with number then i can easily find
    out the number
    but in vain if the TOC ends with like this
    "Uting Tatk and Window Panet 15 New!".
    i could n't find the page number.What will you do if it says:
    "15 ways to find topics 42 new"

  • Extracting the partial string from the string in oracle

    Hello Friends,
    I have a string like this
    var str = '/G/CNH/CNHCornerstone/currentCode/data/Working/Images/ModelImages/png/7402203E-607D-E111-9CA5-005056875BD6.png'
    I want to extract only 7402203E-607D-E111-9CA5-005056875BD6 from the string .
    Please let me know how to implement this ..
    thanks/kumar
    Edited by: kumar73 on Apr 10, 2012 12:34 PM

    hope this works
    set serveroutput on
    declare
      str1 varchar(4000);
      str2 varchar(4000);
    begin
      str1 := '/G/CNH/CNHCornerstone/currentCode/data/Working/Images/ModelImages/png/7402203E-607D-E111-9CA5-005056875BD6.png';
      dbms_output.put_line('string 1 : ' || str1);
      str2 := substr(str1,71);
      dbms_output.put_line('string 2 : '||str2);
    end;
    output
    string 1 : /G/CNH/CNHCornerstone/currentCode/data/Working/Images/ModelImages/png/7402203E-607D-E111-9CA5-005056875BD6.png
    string 2 : 7402203E-607D-E111-9CA5-005056875BD6.png
    PL/SQL procedure successfully completed

  • Breadcrumbs containing string with spaces - generating the anchor

    so I have a website that contains a 'breadcrumbs' line that allows users to click on it, and take them back to the parent page
    eg. "jewellery"
    I simply suffix this string with ".cfm" to generate the anchor / filename
    what's the best way to deal with strings containing spaces?
    eg. "birthday cards"
    As good practice I want to use a more compatiable filename that doesn't include spaces
    eg. "birthday_cards.cfm"
    is the REPLACE command ok to use ? or is preferrable to add an additonal field to the table, called "filename" and store the exact filename in there ?

    option 1
    use quotes like href="http:\\....."
    option 2
    convert spaces to %2B

Maybe you are looking for

  • Move SUP role from Server 2008 R2 to new Site System running Server 2012 R2

    Is it possible to move the primary SUP role which is currently running on a separate site system under Server 2008 R2 (WSUS 3.0 SP2) and move it to a new site system running Server 2012 R2 using the same SUSDB? I've moved the SUP role around before b

  • UIX ERROR data page inputform

    I dragged and dropped a given table as a input form on a uix page. It looked fine in design and preview but not when I ran it. The field names were there but none of the input fields were rendered. I have jdk 1.4.2 are there any other required libs?

  • Cannot open Illustrator CS6 on mac

    Installed CS6 on Mac running 10.7.4.  Cannot open Illustrator InDesign; other porgrams open  fine.  I get a configuraiton error 5 message. Cannot uninstall Illustrator; get an "Uninstall failed" message.

  • 11G- Apache Tomcat support

    Good morning, I have been building a new ADF application, and am trying to deploy it now. I got to correctly deploy to a Oracle WebLogic Server installed on my machine. Ran into many problems when trying to get it to deploy to an Apache Tomcat 6 serv

  • Going from Picassa to 9: what do I do?

    I have 30,000 plus photos in Picassa and have bought Elements 9. Can it read the edits that I have  done already in Picassa? How can 9 access all the photos I have already? And one more ... i wnat to store all photos in external HD, does that presnet