Split string in 2 words

Hello,
If i have the string 'test1 test2-ttt test3'.. how can i split the string in two strings, so the 1st string contains the 1st word and the second the words after the first space?
e.g. in my case str1 = test1 and str2 = test2-ttt test3
i tried with
select substr('test1 test2-ttt test3', 1, instr('test1 test2-ttt test3', ' ', instr(''test1 test2-ttt test3', ' ')+1)-1)
from dual;but it's not the expected result..
Thanks in advance!

did you need somethink like this
select a.word1, substr('test1 test2-ttt test3',length(a.word1)+1,instr('test1 test2-ttt test3',' '))  from
select substr('test1 test2-ttt test3',1,instr('test1 test2-ttt test3',' ')-1) word1 from dual
) a
, dual bEdited by: Adigozalov Gurban on Jan 25, 2011 10:46 AM

Similar Messages

  • Best way to split a single string containing 2 words into word1 and word2

    Whats the best way to take a string containing 2 words and split it into 2 strings ?
    eg. "red ferrari"
    string1 "red"
    string2 "ferrari"

    If your list is always going to have exactly two words, then yes.  Otherwise it depends on your requierments.

  • Split string into two based on end of word and max length

    I have the following procedure, which is passed a comma separated string as it input, and it has to split it into two, and the split has to occur at the end of a word, and the first split part can't be more than 15 in length.
    Is there an more efficient way of achieving this? I have a loop in my main code that calls this procedure and in effect a nested loop has been created here.
    e.g. Hello, everyone, welcome, to, split, string' would be split into 'Hello' and 'everyone, welcome, to, split, string'
    create or replace procedure split_str
                   (pi_str  in  varchar2,
                    po_str1 out nocopy varchar2,
                    po_str2 out nocopy varchar2) is
      i number;
    begin
      if (len(pi_str) <= 15) then
        po_str1 := pi_str;
        po_str2 := NULL;
      else
        i := 1;
        loop
          exit when len(SUBSTR(pi_str, 1 ,INSTR(pi_str, ',', 1, i)-1)) > 15;
          po_str1 := SUBSTR(pi_str, 1 ,INSTR(pi_str, ',', 1, i)-1);
          po_str2 := SUBSTR(pi_str, INSTR(pi_str, ',', 1, i)+2);
          i := i+1;
        end loop;
      end if;
    end split_str; 

    You want to find the last space character before the 15th character.
    x := INSTR ( SUBSTR ( pi_str, 1, 15) , ' ' , -1)Then the first string is SUBSTR(pi_str,1,x) and the second string is SUBSTR(pi_str,x+1)

  • How to write ABAP code to split a sentence into Word by Word and store them

    Hi all,
        I have to split a sentence into word by word and store them into separate columns. This sentence is nothing but a text description (TXTMD) from table TXXXX. The description will have 3 or more than 3 words and LAST word will be <b>always with %</b>'. The following is the sample input data:
    KEY(ORD43)       Description(TXTMD)
    'AAAA'                '1234  ABCD COMPANY USA  80%'
    'BBBB'                '4745  XYZ INC CANADA ABCD  70%'
    For the first record:
      '1234' should stored in to <b>Field 1</b>, 'ABCD COMPANY USA' into <b>Field 2</b> and
    '80%' into <b>Filed 3</b>.
    For the second record:
      '4745' should stored in to <b>Field 1</b>, 'XYZ INC CANADA ABCD'  into <b>Field 2</b> and 70%' into <b>Field 3</b>.
      The first word into Field 1, the last word with % into Field 3 and all middle words into Field 2. The number of words in the sentence could be 3 or more than 3.
      Could you please help in writing the ABAP for this requirement ????
      Thanks in advance.
    Regards,
    Venkat.

    Easy way if you know the length of the field.
    In my example I assumed my field has 12 places.
    DATA: obs TYPE string,
           bkp TYPE char12.
    obs = '12345678901234567890123456789012345678901234567890'.
    DO.
       MOVE obs TO bkp.
       SHIFT obs BY 12 PLACES LEFT.
       write: / bkp.   "Do what you want with bkp variable
       IF obs IS INITIAL.
         EXIT.
       ENDIF.
    ENDDO.

  • Split String into two

    HI,
    How to Split String into two parts at delimiter

    HI,
    REPORT ZSTRING.
    DATA: LENGTH TYPE I,    
          REMAINING_LENGTH TYPE I ,   
          NEXT_POINTER TYPE I    ,   
          FIRST_HALF(20)  TYPE C ,    
          SECOND_HALF(20) TYPE C ,    
          TEMP TYPE I .
    PARAMETER: WORD(35) TYPE C . "INPUT WORD
    START-OF-SELECTION.
    LENGTH = STRLEN( WORD ).      "Length of the input String
    SEARCH WORD FOR '/'.
        IF SY-SUBRC = 0 .  
          IF SY-FDPOS > 0.   
          MOVE WORD+0(SY-FDPOS) TO FIRST_HALF.  
          ENDIF.  
       TEMP = SY-FDPOS + 1. 
       IF TEMP <> LENGTH.    
       NEXT_POINTER = SY-FDPOS + 1.    
       REMAINING_LENGTH = ( LENGTH - SY-FDPOS ) - 1.    
       MOVE WORD+NEXT_POINTER(REMAINING_LENGTH) TO SECOND_HALF.  
       ENDIF.
    ENDIF.
    WRITE:/'Input String:', WORD .
    WRITE:/'First  Half:', FIRST_HALF.
    WRITE:/'Second Half:', SECOND_HALF.
    *-- End of Program
    Reward Points if found helpfull..
    Cheers,
    Chandra Sekhar.

  • Split string into new column

    Hi All,
    Hoping you are able to help.
    I have a table of approx 16 items that I need to split,
    EG:
    CUSTOMER ACCEPTANCE - HAS BEEN DECLINED - DO NOT APPLY TO ACCOUNT
    CUSTOMER ACCEPTANCE -  HAS BEEN ACCEPTED - APPLY TO ACCOUNT
    CUSTOMER ACCEPTANCE - PENDING DECLINE - ESCALATION REQUIRED - RAISED IN PORTAL
    ESCALATION - RAISED - PENDING
    ESCALATION - NOT RAISED - STILL TO BE PROCESSED
    I need to Keep the first two sections, eg CUSTOMER ACCEPTANCE - HAS BEEN DECLINED in one column, and split off the remaining, eg DO NOT APPLY TO ACCOUNT into a new TEMP table to insert as a column into an existing table.
    With little SQL experience, I am having difficulties as they are all of different lengths / criteria etc. Some have 3 hyphens whilst others have 4+
    Is anyone able to help point me in the right direction with this request? I will be greatly appreciated.
    Kind Regards,
    BTMMP

    If you're trying to do this all in a SQL query or stored procedure, then you'll probably get better results on the SQL Server forums. However, if you're working with a PowerShell or VBScript that's doing the work, you're in the right place.
    Here's one example of how you could do what you're describing.  By the way, what do you want to do with the string "CUSTOMER ACCEPTANCE - PENDING DECLINE - ESCALATION REQUIRED - RAISED IN PORTAL"?  Should that be split into "CUSTOMER ACCEPTANCE
    - PENDING DECLINE" and "ESCALATION REQUIRED - RAISED IN PORTAL", or "CUSTOMER ACCEPTANCE - PENDING DECLINE - ESCALATION REQUIRED" and "RAISED IN PORTAL"?
    (In other words, should the script only split off whatever's after the final hyphen, or should it grab the first two pieces of text and split off everything else?)
    Here's an example in PowerShell which assumes that you want to separate out all text after the final hyphen in a string.  It uses a regular expression, though you could accomplish the same thing with Split, Join and Trim operations, if you prefer.
    $string = 'CUSTOMER ACCEPTANCE - HAS BEEN ACCEPTED - APPLY TO ACCOUNT'
    if ($string -match '(.*?)\s*-\s*([^-]*)$')
    $split = $matches[1], $matches[2]
    else
    $split = $string, ''
    Write-Host "Original String: $string"
    Write-Host "First Text : $($split[0])"
    Write-Host "Second Text : $($split[1])"

  • Split String FM

    Hello,
    Does anyone know a standard string FM that split string at an absolut place and consider if the N place is blank or not ?
    My meaning is likely:
    str = 'test one two three'.
    I would like to split str at the 10th place but because it's in a middle of word split it in the 8th place ..
    str1 = 'test one'
    str2 = 'two three'
    and not
    str1 = 'test one t'
    str2 = 'wo three'
    I know that VB has few methods like that, I'm hope abap has it also ..
    Thanks in advance,
    Rebeka

    Hi Rebeka,
                    Please check the following code. This would help. FM 'TEXT_SPLIT' does it correctly.
    DATA: text(50) TYPE c VALUE 'test one two three',
    text1(20) TYPE c,
    text2(20) TYPE c.
    CALL FUNCTION 'TEXT_SPLIT'
      EXPORTING
        LENGTH             = 10
        TEXT               = text
       AS_CHARACTER       =
    IMPORTING
       LINE               = text1
       REST               = text2
    check sy-subrc = 0.
    write :   text1 ,
              text2.
    Reward points if useful.
    Regards
    Abhishek

  • HELP URGENT:; Splitting strings in servlets

    hi ...
    I am trying to access the below servlet from another servlet in iplanet . I have to access a file and arrange the '|' delimited data in the file in a table format like in html ...
    I have used my own function inside the servlets which splits a string based on character ...But I always get
    Internal error: exception thrown from the servlet service function (uri=/servlet/ReportsDataServlet): java.lang.NullPointerException, Stack: java.lang.NullPointerException
    at ReportsDataServlet.split(ReportsDataServlet.java:82)
    at ReportsDataServlet.doPost(ReportsDataServlet.java:56)
    at ReportsDataServlet.doGet(ReportsDataServlet.java:14)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:919)
    at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:483)
    The sample code is shown below....I get the same error when i tries with stringokenizer as well....Pls help me fix this.....
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, Se
    rvletException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    cont=getServletContext();
    out.println("<html><head><title>Reports Data</title></head><body bgcolor=DBD0E2>");
    String repType = request.getParameter("Rep");
    String mon = request.getParameter("month");
    String day = request.getParameter("day");
    String year = request.getParameter("year");
    String repName = repType+"."+mon+"-"+day+"-"+year+".txt";
    BufferedReader in = new BufferedReader( new FileReader("/home/lnayar/baais/xmlServlet/"+rep
    Name));
    String st;
    st = in.readLine();
    cont.log(st);
    int c =0;
    out.println("<table border=\"3\" cellpadding=\"0\" cellspacing=\"0\" width=\"800\"><tr><td>L
    ATA</td><td>WC CLLI</td><td>WC NAME</td><td>ADSL_LOCATION</td><td>ATM FLAG</td><td>ATM RELIEF DATE</td><t
    d>FRAME FLAG</td><td>FRAME RELIEF DATE</td><td>GOLD FLAG</td><td>GOLD RELIEF DATE</td><td>OVERLAY INDICAT
    OR</td><td>COUNT</td></tr>");
    while (st != null)
    c++;
    st = in.readLine();
    StringTokenizer stt = new StringTokenizer(st);
    out.println("<tr>");
    while (stt.hasMoreTokens())
    //out.println("<td>"+stt.nextToken("|")+"</td>");
    out.println("<td>hello</td>");
    out.println("</tr>");
    while (st != null)
    c++;
    st = in.readLine();
    out.println("<tr>");
    Enumeration en = split(st,"|");
    while(en.hasMoreElements())
    out.println("<td>"+en.nextElement()+"</td>");
    out.println("</tr>");
    cont.log("out while");
    out.println("</table>");
    out.println("</body></html>");
    public Enumeration split (String str, String delim)
    Vector v = new Vector();
    int pos_1;
    int pos_2;
    //Set initial delimiter positions...
    pos_1 = 0;
    pos_2 = 0;
    //Start chopping off bits from the string
    //until left boundary reaches the length of string
    while ( pos_1 <= str.length() )
    pos_2 = str.indexOf(delim, pos_1);
    if ( pos_2 < 0 )
    pos_2 = str.length();
    String sub = str.substring (pos_1, pos_2);
    pos_1 = pos_2 + 1;
    v.addElement(sub);
    return v.elements();
    d deeply appreciate if soeone could take a look at the code and tell me exactly where i am going wrong ..... Its URGENT ...
    Thx
    klv

    But there is the while statement which filters null
    values..Which is useless in your case, because you proceed to change the value of st to something else which you don't check for null.
    At any rate, what you have to do is this:
    1. Look at the stack trace to find the line number where the error occurs.
    2. Look at that line in your code.
    3. Look at each object variable in that line. Find out how it became null and fix that.

  • Searching a string in Microsoft word from a Jav Application

    Would appreciate if you could provide me with an example/ suggestion to search for a string in Microsoft Word document from a java aplication. Thanks

    Short and rude answer: STFW.
    Long and polite answer: If you use "java apache word excel" as the criterium to search the web with Google, the first hit is what we are looking for:
    http://jakarta.apache.org/poi/
    Good luck anyway!

  • Replace string in ms word file

    Salue,
    I need to add a functionality to my Java app by allowing the replacement of strings in ms word files.
    Basically I need to use an original MS Word file as template and then populate it with data,
    replacing some keywords. And I need to do this with Java.
    I know MS Word is binary and not text file, so I was wondering if there is any Java API to let me do this?
    Merci, Irene

    Irene,
    It is possible to use ms word(.doc) or openoffice(.odt) templates and populate them with data.
    I came across this solution while trying to convert to pdf, but it is usefull in replacing also.
    import officetools.OfficeFile; // officetools.jar from this website http://www.dancrintea.ro/doc-to-pdf/
    FileInputStream fis = new FileInputStream(new File("your_template.doc"));
    FileOutputStream fos = new FileOutputStream(new File("your_final_result.doc"));
    OfficeFile f = new OfficeFile(fis,"localhost","8100", true);
    *f.replaceAll("hello","salue :) ");*
    f.write(fos);

  • Split string function in oracle ...

    Hello,
    Little question, is there any split string function available in Oracle.
    SQL> select more_info
    2 from dba_advisor_findings;
    MORE_INFO
    Allocated Space:4390912: Used Space:4237403: Reclaimable Space :153509:
    select more_info as Allocated_Space,
    more_info as Used_Space,
    more_info as Reclaimable_Space
    from dba_advisor_findings
    Allocated_Space Used_Space Reclaimable_Space
    4390912 4237403 153509
    Thanks,
    Manish Gupta

    I explored more on SUBSTR and INSTR string functions ... and below is the solution
    select substr(more_info,instr(more_info,':',1,1)+1,instr(more_info,':',1,2)-instr(more_info,':',1,1)-1) as "Allocated_Space",
    substr(more_info,instr(more_info,':',1,3)+1,instr(more_info,':',1,4)-instr(more_info,':',1,3)-1) as "Used_Space",
    substr(more_info,instr(more_info,':',1,5)+1,instr(more_info,':',1,6)-instr(more_info,':',1,5)-1) as "Reclaimable_Space"
    from dba_advisor_findings;
    Allocated_Space
    Used_Space
    Reclaimable_Space
    4390912
    4237403
    153509
    Thanks...

  • How to write ABAP code to split a sentence into Word by Word ???

    Hi all,
    I have to split a sentence into word by word and store them into separate columns. This sentence is nothing but a text description (TXTMD) from table TXXXX. The description will have 3 or more than 3 words and LAST word will be always with %'.
    This description is available on R/3 table and in InfoObject on BW side and this split is required in reporting. Should I split it in R/3 itself or BW side, PLEASE ?
    The following is the sample input data:
    KEY(ORD43) Description(TXTMD)
    'AAAA' '1234 ABCD COMPANY USA 80%'
    'BBBB' '4745 XYZ INC CANADA ABCD 70%'
    For the first record:
    '1234' should stored in to Field 1, 'ABCD COMPANY USA' into Field 2 and
    '80%' into Filed 3.
    For the second record:
    '4745' should stored in to Field 1, 'XYZ INC CANADA ABCD' into Field 2 and 70%' into Field 3.
      The first word into Field 1, the last word with % into Field 3 and all middle words into Field 2.
    Could you please help in writing the ABAP for this requirement ????
    Thanks in advance.
    Regards,
    Venkat.

    Hi,
    in case your text is built in that way for every record you can do the following in routines of the update rules to the 3 fields:
    routine for field 1:
    result = comm_structure-<name of your textfield>(4).
    routine for field 2:
    data: l_length type i.
    l_length = strlen( comm_structure-<name of your textfield> ).
    l_length = l_length - 9.  "the 5 characters at the beginning + 4 at the end.
    result = comm_structure-<name of your textfield>+4(l_length).
    routine for field 3:
    data: l_length type i.
    l_length = strlen( comm_structure-<name of your textfield> ).
    l_length = l_length - 3.
    result = comm_structure-<name of your textfield>+l_length(3).
    hope this helps!
    kind regards
    Siggi

  • FM for to split string

    Hi All,
    Is there a FM available which can split string based on seprator e.g ABC XYZ needs to be separated using space delimeter.
    Thanks!
    Prakash D. Naik

    if you dont know the number of occurrences of the delimeter you can use the following code.
    data: source type string ,
          target type standard table of string .
    source = 'This is for test.' .
    split source at ' ' into table target .
    Regards
    Raja
    PS Kindly post ABAP related questions at
    ABAP Development

  • Split String at delimiter into table.

    Hi Experts,
    I have a requirement wherein i need to split aaaa#bbbbbbbbbbbb#ccc#dddddddddddddddddddddd#e# into internal table as below:
    Header 1
    Header 2
    1
    aaaa
    2
    bbbbbbbbbbbb
    3
    ccc
    4
    dddddddddddddddddddddd
    5
    e
    how can this be done.
    Thanks & Regards,
    Anil

    Hi Ashok,
    split <string> at '#' into table it.  -Doesn't work
    split <string> at SPACE into table it. - Works
    But same statement with '#' is not working.
    Feeling strange.
    Thanks,
    Anil

  • Function module to split strings

    Hi,
    I have a string value ' DBTABLE-FIELDNAME'. I need to split this into 2 strings - The first one is the database table name and the second one is the fieldname. So, the character '-' is the point where the split needs to be done. How can this be achieved. Any FM that I could use?
    Thanks for your help!
    Regards,
    Divyaman Singh Rawat

    Use FM 'STRING_SPLIT'
    REPORT ZEXAMPLE.
    DATA: V_HEAD(10), V_TAIL(10).
    PARAMETERS: P_STR(20),
                P_DEM.
    CALL FUNCTION 'STRING_SPLIT'
         EXPORTING
              DELIMITER = P_DEM
              STRING    = P_STR
         IMPORTING
              HEAD      = V_HEAD
              TAIL      = V_TAIL
         EXCEPTIONS
              NOT_FOUND = 1
              NOT_VALID = 2
              TOO_LONG  = 3
              TOO_SMALL = 4
              OTHERS    = 5.
    IF SY-SUBRC EQ 0.
      WRITE:/ 'HEAD:', V_HEAD,
            / 'TAIL:', V_TAIL.
    ELSE.
      WRITE:/ 'ERROR SPLITTING STRING'.
    ENDIF.
    Regards,
    Joy.

Maybe you are looking for

  • TAX code is not working for a specific company code

    Hi Friends, One tax code is giving error messa ge that it is not maintained in tax procedure, when iam using the same code for another company code it is working fine. Please help me, points are assured. Thanks. Srini

  • Serious bootcamp problem please help.

    I already installed boot camp once, everything was fine. But my windows had a virus, so i decided to delete the partition and make another one. well after i formatted the windows partition and isntalled it, my mac partition was deleted. it had very i

  • Cannot run camtasia studio 6 in firefox but will run in IE and Chrome.

    I am trying to view a camtasia studio 6 video file and it will not run. It runs fine in IE and Chrome!

  • Cursor placement in a Text Field

    Greetings, Here is the setup: Text field with a default value set to : XXX User tabs into the field. Problem: When you tab into the field the entire default value is highlighted Seeking the following solution: How do you tab into a field and get the

  • Custom software component not selectable in Landscape Configurator

    Hello all, I am trying some tutorial about Java development with a track and the developer studio. I have successfully created the software component in my SLD, which is well linked to the NWDI. When creating a track in the Landscape Configurator, ho