How to split a string using IndexOf?

How would you split a string using indexOf and not using the .split method?
Any help is appreciated :D
Message was edited by:
billiejoe

would it be better to use the first or the second?
int      indexOf(int ch)
Returns the index within this string of the first occurrence of the specified character.
int      indexOf(int ch, int fromIndex)
Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
I think the second would be helpful. so how do i read it?

Similar Messages

  • How to Split the string using Substr and instr using loop condition

    Hi every body,
    I have below requirement.
    I need to split the string and append with single quotes('') followed by , (comma) and reassign entire values into another variable. so that i can use it where clause of update statement
    for example I am reciveing value as follows
    ALN varchar2(2000):=(12ERE-3MT-4Y,4IT-5O-SD,OP-K5-456,P04-SFS9-098,90P-SSF-334,3434-KJ4-O28,AS3-SFS0-J33,989-3KL-3434);
    Note: In the above variable i see 8 transactions, where as in real scenario i donot how many transaction i may recive.
    after modification i need above transactions should in below format
    ALTR Varchar2(2000):=('12ERE-3MT-4Y','4IT-5O-SD','OP-K5-456','P04-SFS9-098','90P-SSF-334','3434-KJ4-O28','AS3-SFS0-J33','989-3KL-3434');
    kindly help how to use substr and instr in normal loop or for loop or while loop while modifying the above transactions.
    Please help me to sort out this issue.
    Many Thanks.
    Edited by: user627525 on Dec 15, 2011 11:49 AM

    Try this - may not be the best way but...:
    create or replace type myTableType as table of varchar2(255)
    declare
    v_array mytabletype;
    v_new_str varchar2(4000);
    function str2tbl
             (p_str   in varchar2,
              p_delim in varchar2 default '.')
             return      myTableType
        as
            l_str        long default p_str || p_delim;
             l_n        number;
             l_data     myTableType := myTabletype();
        begin
            loop
                l_n := instr( l_str, p_delim );
                exit when (nvl(l_n,0) = 0);
                l_data.extend;
                l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
                l_str := substr( l_str, l_n+length(p_delim) );
            end loop;
            return l_data;
       end;
    begin
      v_array := str2tbl ('12ERE-3MT-4Y,4IT-5O-SD,OP-K5-456,P04-SFS9-098,90P-SSF-334,3434-KJ4-O28,AS3-SFS0-J33,989-3KL-3434', ',');
          FOR i IN 1 .. v_array.COUNT LOOP
             v_new_str := v_new_str || ''''||v_array(i)||'''' || ',';
          END LOOP;
       dbms_output.put_line(RTRIM(v_new_str, ','));
    end;  
    OUTPUT:
    =======
    '12ERE-3MT-4Y','4IT-5O-SD','OP-K5-456','P04-SFS9-098','90P-SSF-334','3434-KJ4-O28','AS3-SFS0-J33','989-3KL-3434'HTH
    Edited by: user130038 on Dec 15, 2011 12:11 PM

  • How to split a string using sql

    Hi All,
    I've to write a query where I need to split a string, how this can be done? So let's say a column has value as 1,2,3,4,5 and I want to split this string and output it as:
    1
    2
    3
    4
    5
    Please advise.

    Lots of articles:
    Snap this user defined function too:
    CREATE FUNCTION [dbo].[ufn_SplitString_Separator](@InputStr VARCHAR(MAX), @Separator VARCHAR(1))
    RETURNS @tmpTable TABLE (OutputStr VARCHAR(MAX))
    AS BEGIN
    DECLARE @TmpPOS integer
    SET @TmpPOS = CHARINDEX(@Separator,@InputStr)
    WHILE @TmpPos > 0 BEGIN
    IF @TmpPos > 0 BEGIN
    INSERT INTO @tmpTable VALUES (LTRIM(RTRIM(SUBSTRING(@InputStr,1,@TmpPos-1))))
    SET @InputStr = SUBSTRING(@InputStr, @TmpPOS + 1, LEN(@InputStr) - @TmpPos)
    SET @TmpPOS = CHARINDEX(@Separator,@InputStr)
    END ELSE BEGIN
    INSERT INTO @tmpTable VALUES (LTRIM(RTRIM(@InputStr)))
    SET @TmpPos = 0
    END
    END
    IF LEN(@InputStr) > 0 BEGIN
    INSERT INTO @tmpTable VALUES (LTRIM(RTRIM(@InputStr)))
    END
    RETURN
    END
    GO
    And you can use like this:
    SELECT * FROM DBO.[ufn_SplitString_Separator]('1,2,3,4,5',',')
    "If there's nothing wrong with me, maybe there's something wrong with the universe!"

  • How to "split" a string using API 1.3?

    Hi everyone,
    I'm needing to split strings at the slash "/" character.
    Unfortunately, we're using API 1.3, and according to the API, "split" isn't available until 1.4.
    I'm looking for suggestions, help, examples, or alternatives.
    Thanks!

    How about StringTokenizer?

  • How To Split the String for "."

    Hi Friends
    I am Using Following Code to Split one String.
    String str = "Jeetendra.choudhary";
    String[] sp_str = str.split(".");
    wdComponentApi.getMessageManager.reportSuccess(str[0]);
    wdComponentApi.getMessageManager.reportSuccess(str[1]);
    but its throwing null pointer exception. 
    when i am using following code its working fine.
    String str = "Jeetendra/choudhary";
    String[] sp_str = str.split("/");
    wdComponentApi.getMessageManager.reportSuccess(str[0]);
    wdComponentApi.getMessageManager.reportSuccess(str[1]);
    what may be the issue and how to split the string with "." ?
    Thanks & Regards
    Jeetendra

    "." is a special character.
    Use
    str.split("\\.");
    Regards
    Benjamin
    Edited by: Benjamin Hansen on Dec 29, 2009 7:52 AM

  • Need Help in Splitting a String Using SQL QUERY

    Hi,
    I need help in splitting a string using a SQL Query:
    String IS:
    AFTER PAINT.ACOUSTICAL.1..9'' MEMBRAIN'I would like to seperate this string into multiple lines using the delimeter .(dot)
    Sample Output should look like:
    SNO       STRING
    1            AFTER PAINT
    2            ACOUSTICAL
    3            1
    4            
    5            9" MEMBRAIN
    {code}
    FYI i am using Oracle 9.2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    There's this as well:
    with x as ( --generating sample data:
               select 'AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN' str from dual union all
               select 'BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN' str from dual)
    select str,
           row_number() over (partition by str order by rownum) s_no,
           cast(dbms_xmlgen.convert(t.column_value.extract('//text()').getstringval(),1) as varchar2(100)) res
    from x,
         table(xmlsequence(xmltype('<x><x>' || replace(str,'.','</x><x>') || '</x></x>').extract('//x/*'))) t;
    STR                                                S_NO RES                                                                                                
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 1 AFTER PAINT                                                                                        
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 2 ACOUSTICAL                                                                                         
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 3 1                                                                                                  
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 4                                                                                                    
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 5 9" MEMBRAIN                                                                                        
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          1 BEFORE PAINT                                                                                       
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          2 ELECTRIC                                                                                           
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          3 2                                                                                                  
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          4                                                                                                    
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          5 45 caliber MEMBRAIN      
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to split the string by datetime in sql

    Hi,
    How to split the string by datetime in sql, I've a table with comments column stores comments by datetime, while selecting I want to split and show as in rows by each jobref.
    can anyone help me in this please.
    Thanks,

    declare @callcentre table (comments varchar(max),lbiref varchar(200))
    insert into @callcentre
    select '(28/10/2014 14:56:14) xyz ..... call  logged   (28/10/2014 14:56:58) xyz ..... call updated   (28/10/2014 14:57:41)xyz ..... call updated','Vi2910201'
    insert into @callcentre
    select '(29/10/2014 14:56:14) xyz ..... call  logged   (29/10/2014 14:56:58) xyz ..... call updated   (29/10/2014 14:57:41)xyz ..... call updated','Vi2910202'
    insert into @callcentre
    select '(30/10/2014 14:56:14) xyz ..... call  logged   (30/10/2014 14:56:58) xyz ..... call updated  
    output:
    1) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call  logged ,'Vi2910201'
     2) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910201'
    3) 28/10/2014 14:57:41,  (28/10/2014 14:57:41)xyz ..... call updated,'Vi2910201'
    4) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call  logged ,'Vi2910202'
     5) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910202'
    6) 28/10/2014 14:57:41,  (28/10/2014 14:57:41)xyz ..... call updated,'Vi2910202'
    7) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call  logged ,'Vi2910203'
     8) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910203'
    Thanks,
    See this illustration
    declare @callcentre table (comments varchar(max),lbiref varchar(200))
    insert into @callcentre
    select '(28/10/2014 14:56:14) xyz ..... call logged (28/10/2014 14:56:58) xyz ..... call updated (28/10/2014 14:57:41)xyz ..... call updated','Vi2910201'
    insert into @callcentre
    select '(29/10/2014 14:56:14) xyz ..... call logged (29/10/2014 14:56:58) xyz ..... call updated (29/10/2014 14:57:41)xyz ..... call updated','Vi2910202'
    insert into @callcentre
    select '(30/10/2014 14:56:14) xyz ..... call logged (30/10/2014 14:56:58) xyz ..... call updated','Vi2910203'
    SELECT LEFT(p.u.value('.[1]','varchar(max)'),CHARINDEX(')',p.u.value('.[1]','varchar(max)'))-1) AS [Date],
    '(' + p.u.value('.[1]','varchar(max)') AS comments,
    lbiref
    FROM
    SELECT lbiref,CAST('<Root>' + STUFF(REPLACE(comments,'(','</Data><Data>'),1,7,'') + '</Data></Root>' AS XML) AS x
    FROM @callcentre c
    )t
    CROSS APPLY x.nodes('/Root/Data')p(u)
    and the output
    Date comments lbiref
    28/10/2014 14:56:14 (28/10/2014 14:56:14) xyz ..... call logged Vi2910201
    28/10/2014 14:56:58 (28/10/2014 14:56:58) xyz ..... call updated Vi2910201
    28/10/2014 14:57:41 (28/10/2014 14:57:41)xyz ..... call updated Vi2910201
    29/10/2014 14:56:14 (29/10/2014 14:56:14) xyz ..... call logged Vi2910202
    29/10/2014 14:56:58 (29/10/2014 14:56:58) xyz ..... call updated Vi2910202
    29/10/2014 14:57:41 (29/10/2014 14:57:41)xyz ..... call updated Vi2910202
    30/10/2014 14:56:14 (30/10/2014 14:56:14) xyz ..... call logged Vi2910203
    30/10/2014 14:56:58 (30/10/2014 14:56:58) xyz ..... call updated Vi2910203
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to split a string for 2 different matching patterns?

    hey guys
    i'm trying to split a string, using .split(regular expression), if two different pattern matches but i don't know the exact syntax for it. I want to split the string from letters and punctuations.
    This is what i'm doing, obviously it's not working, i'm not too sure if syntax are correct.
    String inputDigit [] = input.split("([a-zA-Z]) (\\p{Punct})");Please help me with this, thank you!

    Can you describe in more detail what you're trying to
    accomplish?ok, basically if you have a string which consists of letters, digits and punctuations. All i'm trying to do or want to do is store all digist within that string into an array. Therefore, i'm using split method to split the string wherever you find a letter or a punctuation. But i don't know what is syntax for using two different patterns at the same time.
    // For example if you have a string "Eeyore 61 2.986PoohPiglet007Kanga-23"
    // i only want: 61 2 986 007 23. I know i can use substring // but that would be a slightly long process

  • Split a string using Match Pattern function

    I am trying to split a response string from a climate chamber into different parts. The string goes something like this: 0030.0\s0034.6\s0080.0\s0083.4. I am using the match pattern function to split the string using \s as the search string. But it is not splitting the string as required. If I use only \ , its working fine. Can anyone please suggest why \s is not being recognised as a part of the input string?
    Subhro.
    Solved!
    Go to Solution.

    Is the string you show in normal display mode or in \ codes display mode?
    Anyway, if you need to match a '\' character you'll have to mask it using \, so the match string would be '\\s' to match '\s'.
    Alternatively you could use spreadsheet string to array with the correct delimiter. For the data you show this would work perfectly.

  • How to split this string(char1)char2(char3)char4 into (char1)char2 , .. etc

    how to split this string (char1)char2(char3)char4 into (char1)char2 , (char3)char4?
    String[] result = "(char1)char2(char3)char4".split("\\(");I want :
    result[0] = "(char1)char2" and
    result[0] = "(char3)char4"
    acutally char1,char2,char3, char4 ... is in the form of the below.
    (any charactors except round brace)any charactors except round brace(any charactors except round brace)any charactors except round brace
    I prefer String.split and Pattern.compile().split.
    Edited by: iamjhkang on Feb 5, 2009 3:37 PM
    Edited by: iamjhkang on Feb 5, 2009 3:41 PM

    iamjhkang wrote:
    especially on
    ?= and ?<
    Thanks.The following:
    (?=...)   // positive look ahead
    (?!...)   // negative look ahead
    (?<=...)  // positive look behind
    (?<!...)  // negative look behindare all "look-arounds". See: [http://www.regular-expressions.info/lookaround.html]

  • How to split a string into tokens and iterate through the tokens

    Guys,
    I want to split a string like 'Value1#Value2' using the delimiter #.
    I want the tokens to be populated in a array-like (or any other convenient structure) so that I can iterate through them in a stored procedure. (and not just print them out)
    I got a function on this link,
    http://www.orafaq.com/forum/t/11692/0/
    which returns a VARRAY. Can anybody help me how to iterate over the VARRAY, or suggest a different alternative to the split please ?
    Thanks.

    RTFM: http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collections.htm#sthref1146
    or
    http://www.oracle-base.com/articles/8i/Collections8i.php

  • How to split a string having string as delimiter instude of char?

    Hello Gurus,
    I want to split the string and work on each split string.
    The following code will do, but not exactly.
    It's split into morethan three strings, where coma find.
    But I want to split it using #,# as delimiter.
    Here is my code:
    //File fileData = new File("myfile.txt");
    // This will have coma separated fields data
    // while traversing this file will readLine() give the string, that is strRecord
    // BufferedReader bfrdRdrObj = new BufferedReader(new FileReader(strDataFile));
    //while ((strThisLine = bfrdRdrObj.readLine()) != null) {..........
    String strRecord = #A001#,#User1#,#this is record, so need to split and place, insert into table#;
    StringTokenizer strTknRec = new StringTokenizer(strRecord,"#,#");
    int iCounter=0;
    while(strTknRec.hasMoreTokens()){
    System.out.println(++iCoutner+"Field: "+strTknRec.nextToken());
    Please, give me hint.
    Thanks in advance.
    ~ SubbaReddy .M

    Hello Guru,
    Here "myfile.txt" CSV file.
    each line represented treated as a record and coma seperated string is treated as fields.
    But, one of the fields data may have the coma in the string itself. So, # or " (double quote) has been place before and end of the field data as a string qualifier.
    //File fileData = new File("myfile.txt");
    // This will have coma separated fields data
    // while traversing this file will readLine() give the string, that is strRecord
    // BufferedReader bfrdRdrObj = new BufferedReader(new FileReader(strDataFile));
    //while ((strThisLine = bfrdRdrObj.readLine()) != null) {..........
    String strRecord = #A001#,#User1#,#this is record, so need to split and place, insert into table#;
    StringTokenizer strTknRec = new StringTokenizer(strRecord,"#,#");
    int iCounter=0;
    while(strTknRec.hasMoreTokens()){
    System.out.println(++iCoutner+"Field: "+strTknRec.nextToken());
    And I would like to run this JRE 1.3.1
    Hope, String.split() in JRE 1.4.0 beta will some what resolve this.
    But, how to do it on JRE 1.3.1
    Please, give me hint.
    Thanks in advance.

  • How to split a string which contents 2byte character

    hi all,
      i wanna split a string into substrings  five bits a time
    the problem is the original string may contents 2byte characters
    and if the split bit is a 2byte character we only take the first four bits.
    the 2byte character is used for the next five bits.
      so could you tell how carry is out.
    thanks in advance

    hi all,
      i wanna split a string into substrings  five bits a time
    the problem is the original string may contents 2byte characters
    and if the split bit is a 2byte character we only take the first four bits.
    the 2byte character is used for the next five bits.
      so could you tell how carry is out.
    thanks in advance

  • How to split a string with a space in between?

    Hi ABAP Guru's,
    Can you please help me out? How can I split a string into two which has a space in between?
    For example: lets suppose the string is 'LA CA USA'. How can I split this string? I have to dynamically determine the number of characters before the space therefore I cannot use number constant such as 2 or 3.
    With best regards,
    Ketan

    Hi
    Try like this
    DATA : opbal TYPE p DECIMALS 2 VALUE 0.
        SELECT * FROM zs_mkpf_mseg
                        into corresponding fields of table it_opbal
                        WHERE werks =  itmat-werks
                        AND matnr = itmat-matnr
                        AND budat = s_budat-low.
      *  sort  it_opbal by budat.
      loop at it_opbal.
    read table it_opbal.
          IF it_opbal-shkzg = 'S'.
            opbal = opbal + it_opbal-menge.
          ELSEIF it_opbal-shkzg = 'H'.
            opbal = opbal + it_opbal-menge * -1.
          ENDIF.
      endloop.
        append opbal TO itab-opbal.
      ENDFORM.                    " opbal_data
    you can also use thi s
    DATA: NAMES(30)    TYPE C VALUE 'Charly, John , Peter',
          NAMES2       TYPE STRING,
          ONE(10)      TYPE C,
          TWO(10)      TYPE C,
          THREE        TYPE STRING,
          FOUR(4)      TYPE C VALUE 'FOUR',
          DELIMITER(2) VALUE ','.
    SPLIT NAMES AT DELIMITER INTO ONE TWO.
    *     ONE contains 'Charly' and TWO contains 'John , Pet'.
    *     SY-SUBRC is 4, because TWO was not large enough to
    *     accommodate the whole of the remaining string
    SPLIT NAMES AT ',' INTO ONE TWO THREE.
    *     ONE contains 'Charly', TWO contains ' John',
    *     THREE contains ' Peter'.
    SPLIT NAMES AT ', ' INTO ONE THREE TWO.
    *     ONE contains 'Charly', THREE contains 'John',
    *     TWO contains 'Peter'.
    CONCATENATE NAMES '' INTO NAMES2 SEPARATED BY SPACE.
    SPLIT NAMES2 AT DELIMITER INTO ONE TWO THREE FOUR.
    *     ONE contains 'Charly', TWO contains 'John',
    *     THREE contains 'Peter ', FOUR is empty.
    SPLIT NAMES2 AT DELIMITER INTO ONE FOUR THREE.
    *     ONE contains 'Charly', FOUR contains 'John',
    *     THREE contains 'Peter', SY-SUBRC is 4, since
    *     FOUR was not large enough (spaces are significant
    *     characters!)
    Reward all helpfull answers
    Regards
    Pavan

  • How to split messages without using Message split (BPM)

    In file to file scenario how to split messages coming from file without using Message split (BPM)

    Thank you very much.

Maybe you are looking for

  • Syncing iPod with iTunes using Windows Vista

    I bought my iPod last December and had an Hp Laptop using Windows Xp. Recently I bought a new computer that has Windows Vista on it and since then I can't sync my iPod. iTunes won't recognise that it's even connected. I have transfered all my music a

  • Transferring photos from iPhone 3GS to Computer

    I know this has been asked probably many times and I tried to click on the link that tells you how to do this. it wont come up and I have scrolled thru many posts. I cant find the information. I need to transfer my pictures from my Camera Roll on my

  • Embed font in editable text field

    Hi, I am trying to embed a font into an editable text box. There is no other type on the page so there are no fonts to choose to embed from the FONT folder. How do I embed the font? I hope that is clear... Thanks a bunch! Linda

  • Not able to start Oracle Intelligent Agent

    Hi to all, I am not able to start the Oracle Intelligent Agent. I am getting the following error. bash-2.05$ agentctl start DBSNMP for Solaris: Version 9.2.0.3.0 - Production on 13-OCT-2008 10:43:56 Copyright (c) 2003 Oracle Corporation. All rights r

  • Program for activating transformations

    Hi All, Can you plz tell me is there any standard program to activate transformations in BI. Thanks, Chella.