How to make a combination substr and instr in javascrip

Hi all

I need to extract information in a javascript function.

In sql, we can do as this substr (: P1_ITEM, 1, instr(:P1_ITEM,'.',1,4)-1)

f.e.
01.02.03.04.05-> 01.02.03.04
001.002.003.004.005-> 001.002.003.004


How do I do it in javascript.

Thanks in advance

lukx

Hi lukx,

You can use the following javascript function:

function processText(pString, pSearchString, pOccurrenceNum)
{
  var j = 0;
  for(var i = 0; i < pOccurrenceNum; i++)
  {
    j = pString.indexOf(pSearchString,j) + 1;
  }
  j = j - 1;
  return pString.substr(0,j);
}

To treat, for example, the second example, you've shown, you would have to make the following call:

processText("001.002.003.004.005", ".", 4)

Maybe this isn't the best solution, but as I saw it in the JavaScript API that indexOf and lastIndexOf are only for the first and the last accident, that's why I included the loop for. I hope this helps.

Kind regards

Sergio

Tags: Database

Similar Questions

  • Substr and InStr

    Hi all

    I have a table where a column has a data character in the format below:

    * '00003434' *.
    * '00123' *.
    * '0000045' *.

    If I want to eliminate all zeros on the left, how can I do using substr and instr? or is there an easier way?

    Thank you

    KK

    Try again with

    Select ltrim ('00003434 ', ' 0') of double;

  • Combination of substring and instring in RTF - dynamic signature images url

    I am unable to use a combination of substring and instring in RTF model.

    I have a BUYER_LAST_NAME column, which has a Jean Dupont value. I like to shoot 'john' on this channel.

    I tried to create a variable using <? xdoxslt:set_variable($_XDOCTX,_'new_name',_'')? >

    So I want to do a get variable using substr and InStr.

    <? xdoxslt:get_variable (substring _XDOCTX, BUYER_LAST_NAME, $(DOCUMENT_BUYER_LAST_NAME, 1, instring(BUYER_LAST_NAME,' ')-1))? >

    The command above does not work as a substring and instring aren't xdoxslt operations.

    I tried to do this using xdofx: <? xdofx:substr (BUYER_LAST_NAME, 1, Instr(BUYER_LAST_NAME,' ')-1)? >

    The above work, but I don't know how to make a variable defined using xdofx. Please help me on this.

    Published:

    I want to use this field in a dynamic signature display. But I can't call substring-before command as part of the url.

    URL: {(concat('${OA_MEDIA}','/purchase_order/signatures/',.//BUYER_FIRST_NAME,'_',.//BUYER_LAST_NAME,'.jpg')}

    I want to change the BUYER_LAST_NAME here.

    I'm working on

    URL: {concat (' ${OA_MEDIA} ',' / purchase_order/signatures /',. / / DOCUMENT_BUYER_FIRST_NAME, "_",. / /, '.jpg')}

    But it does not work.

    ->

    URL: {concat (' ${OA_MEDIA} ','/ purchase_order/signatures /',. / / DOCUMENT_BUYER_FIRST_NAME, '_', substring-before(.//DOCUMENT_BUYER_LAST_NAME, ' '), '.jpg')}

    who is working for me

  • How to use substr and instr, where the line of input Multi text

    Hi all

    with

    data in the form of)

    Select ' Mary America.1234 Southridge Park Dr... Samna Lorie.MO.31234..' double val

    Union of all the

    Select 'Bill Johnson.Apartment 3 b. Sterling.VA.20166.3 Plaza Falke' of the double

    )

    Select

    regexp_substr (shipping_instructions, "[^ #] +' 1, 1") name

    , regexp_substr (shipping_instructions, "[^ #] +' 1, 2") address

    , regexp_substr (shipping_instructions, "[^ #] +' 1, 3") city

    , regexp_substr (shipping_instructions, "[^ #] +' 1, 4") State

    , regexp_substr (shipping_instructions, "[^ #] +' 1, 5") zip

    , regexp_substr (shipping_instructions, "[^ #] +' 1, 6") County

    FROM (select REGEXP_REPLACE (val, ' \.)) () [^.])', ' #\1 ") data shipping_instructions)

    (1)'Mary America.1234 Southridge Park Dr... Samna Lorie.MO.31234..'

    (2)'Bill Johnson.Apartment 3 b. Sterling.VA.20166.3 Falke Plaza. »

    "Mary America. 1234 Southridge Park Dr. Samna Lorie. MO.31234..'

    NAME ADDRESS CITY ZIP County SATE

    ---------                  --------                                ------------           ------           -------    -- -----

    Married America 1234 Southridge Park Dr.    Samna Lorie MO 31234  NULL VALUE

    "Bill Johnson. Apartment 3B. Sterling. VA. 20166. Falke Plaza 3... "

    NAME ADDRESS CITY ZIP County SATE

    ----------------      -----------------        -------       -----        ---         --------

    Bill Johnson apartment 3B Sterling, WILL 20166 3 Falke Plaza.

    Problem

    ---------

    (1) if the value, if the County (if null) value then it shows the ZIP with dot's (.) value, in the 31234 above..,.

    How to solve this problem?

    (2) another possible to fix the code, I want to use substr and InStr.

    (3) who is the best approach?

    Conditions:

    --------------

    (1) shipping_instructions column has the value with "Mary America.1234 Southridge Park Dr... Samna Lorie.MO.31234... »

    This means it combined all the similar name, address, city, State, zip

    (2) we insreted in the table separately.

    =========================

    / * Use Substr and Instr * /.

    =========================

    I used substr and instr, but I'm getting the money results (no point in the address).

    "America Mary. 1234 Southridge Park Dr. Samna Lorie.MO.31234..'


    NAME ADDRESS CITY ZIP County SATE

    ---------                  --------                                ------------           ------           -------    -- -----

    Mary America 1234 Southridge Park Dr. Samna Lorie MO 31234  NULL VALUE

    But I need the results (no point in the address)

    NAME ADDRESS CITY ZIP County SATE

    ---------                  --------                                ------------           ------           -------    -- -----

    Mary America 1234 Southridge Park Dr.    Samna Lorie MO 31234  NULL VALUE

    Hello

    994122 wrote:

    Hello

    (1) how do to do this, use the substr and instr functions?

    Thank you

    You can't do all the work with SUBSTR and INSTR; you need regular expressions to obtain a string delimited by a #.

    Once you have such a string, then you can use SUBSTR and INSTR (instead of REGEXP_SUBSTR) to get the separate secondary strings:

    WITH got_delimited_string AS

    (

    SELECT REGEXP_REPLACE (val

    , '\. ([^ .]| $)'

    , '#\1'

    ) AS delimited_string

    FROM the data

    )

    got_pos AS

    (

    SELECT delimited_string

    , INSTR (delimited_string, "#", 1, 1) AS pos_1

    , INSTR (delimited_string, "#", 1, 2), pos_2

    , INSTR (delimited_string, "#", 1, 3) AS pos_3

    , INSTR (delimited_string, "#", 1, 4) AS pos_4

    , INSTR (delimited_string, "#", 1, 5) AS pos_5

    , INSTR (delimited_string, "#", 1, 6) AS pos_6

    OF got_delimited_string

    )

    SELECT SUBSTR (delimited_string, 1, pos_1 - 1) AS the name

    SUBSTR (delimited_string, pos_1 + 1, pos_2 - (pos_1 + 1)) AS address

    SUBSTR (delimited_string, pos_2 + 1, pos_3 - (pos_2 + 1)) AS city

    SUBSTR (delimited_string, pos_3 + 1, pos_4 - (pos_3 + 1)) AS State

    REPLACE (SUBSTR (delimited_string, pos_4 + 1, pos_5 - (pos_4 + 1))

    , '.'

    )                                                           AS zip

    SUBSTR (delimited_string, pos_5 + 1, pos_6 - (pos_5 + 1)) AS the County

    OF got_pos

    ORDER BY delimited_string

    ;

  • Need help with Substr and Instr

    I have a request

    Select msg

    from table_a

    She returned as log messages below

    Continued in logid = > 241153 < for oid = > 1621 <, GoC = > 795, bday = > 01.04.2013 <

    If the message contains logid = > then I want to display

    Continued in logid = > 241151 <

    for example

    case

    When the msg like ' % logid = > %'

    then

    I tried the combinations of substr and instr, but cannot make it work

    Any help appreciated

    Gus

    SQL >-samples:

    SQL > with t as

    2 (choose "continued in logid-online 241153< for="" oid="">1621<, gdc="">795, bday-online 01.04.2013")<;' str="" from="" dual="" union="">

    3 select "continued in pid-online 241153< for="" oid="">1621<, gdc="">795, bday-online 01.04.2013"<;' str="" from="">

    4)

    5. Select case-sensitive

    6 when instr (str, 'logid') > 0

    7 then substr (str

    8, instr (str, ' > ', 1, 1) + 1

    9, instr(str, '<', 1,="" 1)-instr(str,="" '="">', 1, 1)-1

    10                      )

    11 another null - or what you want / need

    12 end str

    13 t;

    STR

    ------------------------------------------------------------------------

    241153

    2 selected lines.

  • substr and instr - get all the characters after the last.

    I have a few fields tbl as follows

    ABC, 123, xyz, 234

    123, ggg, ppp, rrr

    SSS/bbb/444/a

    BB/11

    XX/bb/f

    I want to choose any characters after the last.

    so the above might give

    234

    RRR

    one

    11

    f

    played with substr and instr but have not been able to figure it out yet. He should get one after last chain / no matter where / is or how they are.

    Here is an example

    Select

    substr ("123/dd/gg ', instr (substr (" 123/dd/gg ', instr ("123/dd/gg ', ' /'") + 1 "), ' / ') + 3")

    of the double

    substr ("123/dd/gg ', instr('123/dd/gg','/',-1,1) + 1")

  • How to make more old Hoyle and broderban card games to work in mode full screen on my Sony notebook with Windows 7

    How to make more old Hoyle and Broderband card games to work in mode full screen on my Sony notebook with Windows 7

    Hi Gary,.

    1. what version of Hoyle card games you try to play?

    Try the game in compatibility mode. To install the software in compatibility mode

    1 right click on the Setup file, and then selectProperties.

    2. click on thecompatibility tab.

    3. incompatibility mode, check the run this program in compatibility mode for: option.

    4. Select one of the following operating systems:Windows 98/Me/XP/2000 , from the options offered.

    5. click onapply and OK.

    See the link below for more information on compatibility mode:

    Make older programs in this version of Windows
    http://Windows.Microsoft.com/en-us/Windows7/make-older-programs-run-in-this-version-of-Windows

    If the problem is only with these games you may need to contact the manufacturer about this issue.

    Bindu R - Microsoft Support
    Visit our Microsoft answers feedback Forum and let us know what you think

  • I buy a new mac. How to make my adobe account and my current computer applications to the new?

    I buy a new mac. How to make my adobe account and my current computer applications to the new?

    You should only install and connect on the new machine.  Your license allows you to have two functional facilities, so if you want you can keep the original as a backup.  If yu can just log out of the old machine and will release that the activation of another facility elsewhere.

    Download/install the desktop application, connect and install applications subscription.

    https://helpx.Adobe.com/creative-cloud/help/download-install-app.html

  • substr and instr EQL

    Another question EQL. Is there an equivalent to substr and instr EQL?

    Published by: bewise on June 28, 2012 17:39

    Not at the moment. Discover the v2.3 EQL language reference guide here for more details.

    http://docs.Oracle.com/CD/E29805_01/QueryLangRef.PDF

  • data of cutting using substring and instring, and storage in a new table

    Hi all

    I have an emp_address 2tables, address as below:
    ---------------------------------------------------------------
    create the table emp_address (emp_id varchar2 (10), address varchar2 (100));

    Insert into EMP_ADDRESS
    (EMP_ID, ADDRESS)
    Values
    ('101', 'street1 fremont CA 94538');
    Insert into EMP_ADDRESS
    (EMP_ID, ADDRESS)
    Values
    ("102", "Street.2 fremont, CA 94537');
    COMMIT;


    create the address table (emp_id varchar2 (10), street varchar2 (20), city varchar2 (15), State varchar2 (10), zip varchar2 (10));

    -----------------------------------------------------------------------------
    Emp_address data as below:

    emp_id address

    street1 101 fremont CA 94538

    102 fremont, CA 94537 Street.2

    ------------------------------------------------------------------------------
    now I read data emp_address and split the data of the address column and record these data in the address table like as below

    emp_id Street City State Zip Code
    street1 101 fremont, ca 94538
    102 fremont, ca 94537 Street.2

    -------------------------------------------------------------------


    I'm trying to divide these data using substring and instring. Actually my problem was between the data a few times I have 1tab or 2tabs and sometimes 3tab. If the number of tab spaces is not constant.

    So can u help me in this case.

    Thanks in adavnce

    position of reference BluShadow

    WITH emp_address AS (SELECT   '101' emp_id,
                                  'street1 fremont CA 94538' address
                         FROM     DUAL
                         UNION ALL
                         SELECT   '102',
                                  'street2  fremont CA 94537'
                         FROM     DUAL),
        emp_address_list_temp AS
          (SELECT       emp_id,
                        SUBSTR (
                          address,
                          DECODE (LEVEL,
                                  1, 1,
                                  INSTR (address, ' ', 1, LEVEL - 1) + 1
                                 ),
                          DECODE (
                            INSTR (address, ' ', 1, LEVEL),
                            0,
                            LENGTH (address),
                            INSTR (address, ' ', 1, LEVEL)
                            - DECODE (LEVEL,
                                      1, 0,
                                      INSTR (address, ' ', 1, LEVEL - 1)
                                     )
                            - 1
                          )
                        )
                          address,
                        LEVEL rn
           FROM         emp_address
           CONNECT BY   LEVEL <=
                          LENGTH (address) - LENGTH (REPLACE (address, ' ')) + 1
           GROUP BY     emp_id, address, LEVEL),
        emp_address_list AS
          (SELECT   emp_id,
                    address,
                    ROW_NUMBER () OVER (PARTITION BY emp_id ORDER BY rn) rn
           FROM     emp_address_list_temp
           WHERE    TRIM (address) IS NOT NULL)
    SELECT     emp_id,
               (SELECT   address
                FROM     emp_address_list e2
                WHERE    e2.emp_id = e1.emp_id
                     AND rn = 1)
                 street,
               (SELECT   address
                FROM     emp_address_list e2
                WHERE    e2.emp_id = e1.emp_id
                     AND rn = 2)
                 city,
               (SELECT   address
                FROM     emp_address_list e2
                WHERE    e2.emp_id = e1.emp_id
                     AND rn = 3)
                 state,
               (SELECT   address
                FROM     emp_address_list e2
                WHERE    e2.emp_id = e1.emp_id
                     AND rn = 4)
                 zip
    FROM       emp_address_list e1
    GROUP BY   emp_id
    
  • SUBSTR and INSTR function

    Hi gurus,

    I have the data as follows:

    data
    -----------------------------------------------------------------------------------------------------------------------
    ' BIDIE01H / TXT:ZUNE = HA011, CellIndex = 144 /CAI:452 - 01-32201-47001 / CAI:45201F7dc9b79a'
    ' BIDIE01H / TXT:ZUNE = HA111, CellIndex = 124 /CAI:452 - 01-32201-471 / CAI:45201F7dc9b79b'


    and I'm writing a SQL results:

    CAI
    ---------
    452 01-32201-47001
    452 01-32201-471

    Any idea to do? I tried around with SUBSTR and INSTR functions but not yet sucessed.

    Thank you
    Alex

    something like:

    with my_tab as (select 'BIDIE01H/TXT:ZUNE=HA011, CellIndex=144 /CAI:452-01-32201-47001/CAI:45201F7dc9b79a' col1 from dual union all
                    select 'BIDIE01H/TXT:ZUNE=HA111, CellIndex=124 /CAI:452-01-32201-471/CAI:45201F7dc9b79b' col1 from dual)
    -- end of mimicking your data: USE SQL below:
    select substr(col1, instr(col1, '/CAI:', 1) + 5, instr(col1, '/CAI:', 1, 2) - instr(col1, '/CAI:', 1) - 5 ) CAI
    from my_tab
    
    CAI
    --------------------------------------------------------------------------------
    452-01-32201-47001
    452-01-32201-471     
    
  • How to use Substr and Instr to get data from a file

    Hi I have a script

    I get a file like this

    1.20, ram, sales

    I get a file as these data as a column

    I want to divide these data into 4 different columns as

    1 20 sales of ram

    Hello

    This query will help you.

    Select

    SUBSTR (C1, 0, INSTR(C1,',')-1).

    SUBSTR (C1, INSTR (C1, ',') + 1, INSTR(C1,',',1,2)-INSTR(C1,',',1,1)-1),

    SUBSTR (C1, INSTR(C1,',',1,2) + 1, INSTR(C1,',',1,3)-INSTR(C1,',',1,2)-1).

    SUBSTR (C1, INSTR(C1,',',1,3) + 1, INSTR(C1,',',1,4)-INSTR(C1,',',1,3)-1)

    SUBSTR (C1, INSTR(C1,',',1,3) + 1)

    BeO

    Select 1, 20, ram, C1 double sales

    )

    Remember that a comma is not really safe as field separator

    Post edited by: DecaXD

  • A string into the text and numbers using SUBSTR and INSTR

    I have the sample data. I know it's terrible database designed for a combination of text and numbers in the same field, but I can't change the business process.

    That's what I have so far:

    set linesize 5000
    
    WITH table_data
         AS (SELECT 'R: JASON BOURNE 12341560' str FROM DUAL UNION ALL
             SELECT 'R: FATS DOMINO 23432342' str FROM DUAL UNION ALL
             SELECT 'R: MARTIN LUTHER KING 3334156' str FROM DUAL UNION ALL
             SELECT 'R: TOM CRUISE 6547123' str FROM DUAL UNION ALL
             SELECT 'R: TOMMY DE GROOT 1212124' str FROM DUAL UNION ALL
             SELECT 'R: GRIM REAPER 1345245' str FROM DUAL UNION ALL
             SELECT 'R: DOCTOR DEATH THE FIRST SMITH 24356178' str FROM DUAL)
    SELECT str
         , TRIM(SUBSTR(str, INSTR(str, ' ', 1, 1), INSTR (str, ' ', 1, 2) - INSTR (str, ' ', 1, 1))) first_name
         , REPLACE(SUBSTR(str, INSTR (str, ' ', 1, 2)+1, 999), SUBSTR(str,LENGTH(str)-6,7), '') last_name
         , SUBSTR(str,LENGTH(str)-6,7) emp_num
      FROM table_data;
    
    STR                                      FIRST_NAME    LAST_NAME                 EMP_NUM
    ---------------------------------------- -----------------------------------------------
    R: JASON BOURNE 12341560                 JASON         BOURNE 1                  2341560
    R: FATS DOMINO 23432342                  FATS          DOMINO 2                  3432342
    R: MARTIN LUTHER KING 3334156            MARTIN        LUTHER KING               3334156
    R: TOM CRUISE 6547123                    TOM           CRUISE                    6547123
    R: TOMMY DE GROOT 1212124                TOMMY         DE GROOT                  1212124
    R: GRIM REAPER 1345245                   GRIM          REAPER                    1345245
    R: DOCTOR DEATH THE FIRST SMITH 24356178 DOCTOR        DEATH THE FIRST SMITH 2   4356178
    
    7 rows selected.
    

    I need to:

    1 extract the first name - which is always the first name after the 'r' - I've got that little works very well.

    2 extract the name - should be the last word before the number, if e.g. for the last night, I wish only that 'SMITH' and 'KING' for the 3rd line and "GROOT" for the 5th line.

    3. remove the number at the end, regardless of the length - some of the examples above are 8 long numbers so my attempt above does not work.

    I can't use any REGEXP or REGEXP_SUBSTR because they are not registered in the EUL I'm using discoverer, I can only use INSTR AND SUBSTR.

    I was wondering if someone might be able to help please?

    Any advice much appreciated.

    Thank you

    AW, go on them, as it's Christmas, I'm feeling generous...

    SQL > ed
    A written file afiedt.buf

    1. WITH table_data (SELECT "r: JASON BOURNE 12341560' DOUBLE UNION ALL STR ')
    2. SELECT "r: FATS DOMINO 23432342' str OF DOUBLE UNION ALL.
    3. SELECT "r: MARTIN LUTHER KING 3334156' str OF DOUBLE UNION ALL.
    4. SELECT "r: TOM CRUISE 6547123' str OF DOUBLE UNION ALL.
    5. SELECT "r: TOMMY GROOT 1212124' str OF DOUBLE UNION ALL.
    6. SELECT "r: GRIM REAPER 1345245' str OF DOUBLE UNION ALL.
    7. SELECT "r: DOCTOR DEATH FIRST SMITH 24356178' FROM DUAL str.
    8                     )
    9 select substr (str, 1, instr(str,' ')-1) as a first name
    10, substr (substr (str, 1, instr(str,' ',-1)-1), instr (substr (str, 1, instr(str,' ',-1)-1),' ', 1) + 1) as last_name
    11, substr (str, instr (str, ' ',-1) + 1) as emp_num
    12 years of (select replace (str,'R: ') as str)
    table_data 13
    14*        )
    SQL > /.

    FIRST_NAME LAST_NAME EMP_NUM
    ---------------------------------------- ---------------------------------------- ----------------------------------------
    JASON BOURNE 12341560
    FATS                                     DOMINO                                   23432342
    MARTIN                                   KING                                     3334156
    TOM                                      CRUISE                                   6547123
    TOMMY                                    GROOT                                    1212124
    GRIM                                     REAPER                                   1345245
    DOCTOR SMITH 24356178

    7 selected lines.

  • How to change the location of the @ how to make the Euro symbol and where is 'hash '?

    I am a proud new owner Portege M300. Now all I need? knowledge is:

    -keyboard looks liks the sign @ is above the 2. In fact, it's above the apostrophe, where the quote is true. I want to have the @ sign overcoming the 2 because that's what I'm used to =. How I change these autour?

    -How to make the Euro sign (as £ and $)?

    -Why is£ 3 rather than the 'hash' sign that is posted above? How to make the sign of 'hash '?

    Hello

    Before you can perform any discussion can you please tell me in which country is your laptop bought and what specific keyboard of the country to unity? Each cell has a specific keyboard of the country.

  • OfficeJet pro 8600 printer-how to make this program work and installation?

    I have problems printing. I wonder how to ste it to the top and do work.

    Moved from feedback

    Original title; printer Officejet pro 8600

    Hi David,

    1. what operating system is installed?

    2. what security software is installed?

    You can go through the printer manual to know how to set up the printer and make it work.

    You can also refer to these items and check if that helps.

    http://h30434.www3.HP.com/T5/printer-all-in-one-install-setup-e-g-Windows-8/How-do-I-install-printer-software-on-HP-OfficeJet-Pro-8600/TD-p/1123283

    http://h30434.www3.HP.com/T5/forums/SearchPage/tab/message?filter=labels%2Clocation&location=Forum-Board%3AInstall&q=OfficeJet+Pro+8600+printer

    Let us know if you need assistance with any windows problem. We will be happy to help you.

Maybe you are looking for