How to make an substr and instr combination  in javascrip

Dear all,
I need to extract some information in a javascript function.
In sql we can do like 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 I can 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 process, for example, the second example you showed, you would have to do the following call:
processText("001.002.003.004.005", ".", 4)Maybe this is not the best solution but as I've seen in the javascript API that indexOf and lastIndexOf are only for the first and last occurrence, that's why I included the for loop. Hope this helps.
Regards,
Sergio

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 make Sales group and office field mandatory in VA01 first screen

    hi gurus,
    can anybody tell me how to make Sales group and sales office mandatory field on VA01 tcode first screen. i have requirement to make it compulsary on the first screen otherwise they wont be able to goto next screen.
    will reward points for sure
    thanks
    mandy

    Hi! Mandy,
    Try using t.code SHD0, choose your transaction variant here, further choose your screen variant.
    Next select your screen variant and in the Menu bar select Variant> change with processing>Make repairs in foreign namespaces only if they are urgent> Continue(Enter)>again 'enter'>Object can only be created in SAP package>continue(enter)> Exit and save >This variant contains other screens, adopt these as well?>enter>enter> scroll down to the entry required by you make the necessary changes(Output only, invisible or required) and save.
    The system will prompt to assign a package and request enter the necessary values.
    Provide your feedback.
    Regards,
    PATHIK

  • How to make the dblink and what is the use of this

    plz any body tell me "how to make the dblink and what is the use of this"
    sujit

    Do you understand how to make the Slider work using code to read its value?  You will need to look into that in order to do this.
    What you can do is have the yello rectangle be a movieclip that sits over the red rectangle and use the Slider to control the yellow rectangle's alpha property from 0 to 1.  That way the yellow will gradually fade as you slide.
    What you will then need  to do is figure out how to make the number of dots that appear reduce from 15 to 8 over the same range of the slider.  You need to use the fractional value from the slider to decide how many dots either appear or do not appear.
    You should not start new postings for the same topics that you arlready have postings for.  Doing so in the future might result in them being removed.

  • How to make New Document and Upload Document to have same Content Type in Document Library in Sharepoint 2010

    Hi,
    How to make 'New Document' and 'Upload Document' to have same content type(Custom) in Document Library in Sharepoint2010.
    Note : I have created custom Content Type since I have custom columns along with upload column..
    Regards, Shreyas R S

    go to library settings 
    Change new button order and default content type
    set your custom content type to be #1
    when you upload new document it will automatically have your custom content type
    Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010

  • How to make your iPad and iPhone commicate with each other

    How to make your iPad and iPhone commicate with each other

    this is very easy...
    firstly disconnect the DSL modem for the linksys..
    then connect the computer to the linksys router (port 1/2/3/4)..
    then access the linksys setup UI
    open ur web browser
    site: http://192.198.1.1/
    username: [blank]
    password: admin
    now hook up the westell modem.. and goto the status page ...
    check Internet IP.
    if then Internet IP is 192.168.1.* then,
    disconnect the westell from the router and goto the setup page.
    change the LOCAL IP address to 192.168.2.1 (notice the 2.1 and not 1.1)
    save settings....
    connect the westell and viola ur online...
    if the Internet IP is 0.0.0.0 then
    goto the setup page and change the 'Internet connection Type' to 'PPPoE'
    once done the page changes and give u a place to enter a username and a password.. this username and password is given by verizon..
    sud be something like '[email protected]'
    once done save settings...
    goto the status page and hit connect... give it a few moments... u shud get a Internet ip address... if u get one ur online if not then power cycle the entire network. and try check to see if u get an ip..
    hope this helps...
    cheers..
    Life is short... So get movin !!!
    DopeLorD

  • 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 am trying to write a SQL to get the results:
    CAI
    452-01-32201-47001
    452-01-32201-471
    Any idea to get it done? I did try around with SUBSTR and INSTR functions but not yet sucessed.
    Thanks,
    Alex

    select substr (str, instr (str, '/CAI:') + 5
                  , (instr (str, '/CAI:', -1) - instr (str, '/CAI:'))-5
      from dataas in
    SQL> with data
      2  as
      3  (select 'BIDIE01H/TXT:ZUNE=HA011, CellIndex=144 /CAI:452-01-32201-47001/CAI:45201F7dc9b79a' str from dual union all
      4  select 'BIDIE01H/TXT:ZUNE=HA111, CellIndex=124 /CAI:452-01-32201-471/CAI:45201F7dc9b79b' from dual
      5  )
      6  select substr (str, instr (str, '/CAI:') + 5
      7                , (instr (str, '/CAI:', -1) - instr (str, '/CAI:'))-5
      8                )
      9    from data
    10  /
    SUBSTR(STR,INSTR(STR,'/CAI:')+5,(INSTR(STR,'/CAI:',-1)-INSTR(STR,'/CAI:'))-5)
    452-01-32201-47001
    452-01-32201-471

  • How to make own editor and call it?

    could you please tell me how to make own editor and call it on a clicking of a push button corresponding to an test Item

    In the Object Navigator... just click on the 'Editor' Node and press the '+' (Create) button....
    Set then any properties as you like....
    So simple...
    Greetings,
    Sim

  • How to make an ebook and sell it on the ibook or app store??

    How to make an ebook and sell it on the ibook or app store??
    Can anybody help me please T^T
    By the way I'm in Thailand and want to sell my ebook around the world.
    This is my dream ^^.. Help me please...

    Hi,
    Start with the ADC iOS dev center here.
    http://developer.apple.com/devcenter/ios/index.action
    Carolyn

  • Substri and instr problem --Please help

    Hi ,
    I would like to get the find tablename starts with 'EXP' using substring and instring . I am using oracle 9i. Please help me out
    Example : 'Schema.explogtable'
    I will use table name ' EXP' in one of my procedure as input parameter to procedure
    If tablename= substr('schema.explogtable','instr('schema.explog','.',1,3) then
    Execute Procedure1('tablename')
    Else
    Execute procedure2('tablename')
    I would appreciate your help
    Regards,
    Clarkc

    ClarkC,
    Here just replace procedure1 and procedure2 with your procedure names;
    create table temp_table
    ( table_name varchar2(30)
    insert into temp_table values ('TESTME.MY_OBJECTS');
    insert into temp_table values ('TESTME.OBJECTS');
    insert into temp_table values ('ABC.ECFOBJECTLOG');
    insert into temp_table values ('XYZ.BDEOBJECTTABLE');
    insert into temp_table values ('ABC.ABCTABLE');
    insert into temp_table values ('ZYD.CLIENTTABLE');
    insert into temp_table values ('NMS.CLIENTLOGTABLE');
    COMMIT;
    pl/sql anonymous blocks  I defined 2 variables for readibility and understanding
    DECLARE
       CURSOR tcur
       IS
          SELECT table_name
          FROM temp_table;
       table_name   VARCHAR2 (40);
       my_table     VARCHAR2 (40);
    BEGIN
       FOR cur IN tcur
       LOOP
          my_table     := NULL;
          my_table     := cur.table_name;
          table_name   := SUBSTR (my_table, INSTR (my_table, '.') + 1);
          IF (table_name LIKE ('%OBJ%'))
          THEN
             DBMS_OUTPUT.put_line ('table_name containing OBJ=' || table_name);
             -- NOTE : CALL YOUR PROCEDURE1 HERE for tables containing OBJ;
            procedure1(table_name);
          ELSE
             DBMS_OUTPUT.put_line('table_name  not containing OBJ=' || table_name);
               -- NOTE : CALL YOUR PROCEDURE2 HERE for tables not containing OBJ;
            procedure2(table_name);
          END IF;
       END LOOP;
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line (SUBSTR (SQLERRM, 1, 300));
          RAISE;
    END;
    Here is the output of the above block
    table_name containing OBJ=MY_OBJECTS
    table_name containing OBJ=OBJECTS
    table_name containing OBJ=ECFOBJECTLOG
    table_name containing OBJ=BDEOBJECTTABLE
    table_name  not containing OBJ=ABCTABLE
    table_name  not containing OBJ=CLIENTTABLE
    table_name  not containing OBJ=CLIENTLOGTABLEHope this helps
    Regards
    Edited by: OrionNet on Jan 17, 2009 11:48 AM

  • How to make an before and after effects?

    So, I want to make a video that show the audience this is before and after the edit. And i want to make it look like this YouTube Rewind 2014: Behind the Scenes - YouTube
    How to make it?
    Thanks:)

    Really? You take footage of you shooting the video with another camera then you edit it together with shots of the finished project. If you want to show before and after shots of an effect you just put the original footage on top and animate a mask or opacity to reveal the rendered effect below.
    If you can't figure out how to make a before and after then you will have a very difficult time doing any effects using AE because there is absolutely nothing in this before and after but very basic editing and masking.

  • HT1420 How to make Apple ID and iCloud the same Id?

    How to make Apple ID and iCloud ID the same after they have been created?
    iTunes keeps asking for ID and passwords that were created differently.

    You can't im afraid. I wanted to do the same and got the following from Apple:
    I am sorry, you cannot update your email address to MobileMe address as each Apple ID is unique.
    Ross, I would like to let you know that, you cannot change your Apple ID if it was at any time a .Mac or MobileMe email address, even if your subscription has ended or been canceled.
    The email address that ends in .me is already an Apple ID as well, as when you set up a MobileMe email its automatically set up as an Apple ID. So you cannot use this email address on another account. It is permanently associated with your MobileMe Apple ID.
    This article provides helpful information when choosing which Apple ID to use with iCloud:
    Apple IDs and iCloud
    http://support.apple.com/kb/HT4895
    This page also covers topics such as moving MobileMe accounts to iCloud, managing your Apple ID, and how to get content purchased with multiple Apple IDs onto your iOS device.
    I hope this information was helpful. If you require further assistance, please do not hesitate to reply to this email and I will be more than happy to assist you further.
    Sincerely,
    Thenmozhi
    iTunes Store Customer Support
    http://www.apple.com/support/itunes/ww/
    I wrote back and tried to escialte the issue but got no where. The whole thing is very disappointing and I hope Apple sort it out eventually.

  • Hello, i would like to know how to make horizontal sites and it moves with the scroll

    Hello, i would like to know how to make horizontal sites and it moves with the scroll

    Hi
    You can refer to these videos :
    http://www.lynda.com/Muse-tutorials/basics-horizontal-scrolling-websites/108131/115685-4.h tml
    https://www.youtube.com/watch?v=gZI_K1TXqOM
    Thanks,
    Sanjit

  • How to make the values of a combination graph (bar and line) visible always

    Hi ,
    I am using jdev 11.1.1.6
    i have created a combination graph which has a bar and line.
    The data with respect to bar and graph were only visible when i keep the mouse pointer on it.
    i need to set the values visible always.
    kindly let me know how to make it.
    In pie graph its by default showing the data always.
    regards
    Siva

    Hi Sameh Nassar,
    Thanks for the input, am using the combination graph and i dont have this property added till now.
    i tried adding them manually in source but it didn't work. so I assume that this property is good with pie chart alone.
    please correct me if am wrong.
    This is my combination graph structure.
        <dvt:comboGraph id="comboGraph1"
                          value="#{bindings.testVO1.graphModel}"
                          subType="COMBINATION_VERT_ABS_2Y" shortDesc="Graph 1">
            <dvt:background>
              <dvt:specialEffects/>
            </dvt:background>
            <dvt:graphPlotArea/>
            <dvt:seriesSet markerDisplayed="true">
              <dvt:series lineWidth="0"/>
            </dvt:seriesSet>
            <dvt:o1Axis/>
            <dvt:y1Axis/>
            <dvt:y2Axis/>
            <dvt:legendArea automaticPlacement="AP_NEVER"/>
            <dvt:graphTitle text="Combination graph"/>
            <dvt:o1Title text="x axis"/>
            <dvt:y1Title text="y1 axis"/>
             <dvt:y2Title text="y2 axis"/>
          </dvt:comboGraph>
    regards
    Siva

  • SUBSTR and INSTR query

    Hello all,
    I need help in simple query how can show only MCCODE
    SELECT SUBSTR('VMTOPIC=MCCODE', INSTR('VMTOPIC=MCODE', 'VMTOPIC=')+8,20) AS output  FROM DUAL;But also when i used
    SELECT SUBSTR('VMTOPIC=MCCODE', INSTR('VMTOPIC=MCODE', 'HHH')+8,20) AS output  FROM DUAL;show same results, what i need only if words begin with " VMTOPIC= " retrived characters after "VMTOPIC=".
    regards
    Dheya

    Hi, Dheya,
    Here's one way:
    SELECT  SUBSTR ( str
                , INSTR ( str || 'VMTOPIC='
                            , 'VMTOPIC='
                     ) + 8
                , 20    -- or omit this argument
                )       AS output 
    FROM    table_x
    ;where tabe_x.str is the string you need to test.
    You could also do this with REGEXP_SUBSTR or REGEXP_REPLACE, but you can do this easily enough without any slow regular expressions.
    973907 wrote:
    ... But also when i used
    SELECT SUBSTR('VMTOPIC=MCCODE', INSTR('VMTOPIC=MCODE', 'HHH')+8,20) AS output  FROM DUAL;show same results, what i need only if words begin with " VMTOPIC= " retrived characters after "VMTOPIC=".That's because 'HHH' wasn't found, and so INSTR returned 0. SUBSTR treats 0 like 1 in its 2nd argument, so, using that expresssion, not fnding the string is te same as finding it at position 1.
    Of couse, looking for 'HHH' in a string that cotains 'VMTOPIC=' isn't the problem here; the real problem is looking for 'VMTOPIC=' in a string that doesn't contain it.
    Making a special case when INSTR returns 0, as Solomon suggested, is one way to get around the problem. Another is what I posted above, which guarantees that INSTR will never return 0. If the 'VMTOPIC=' is not found in str, then lookng for it in str || 'VMTOPIC=' will cause INSTR to return a very high number; so high that SUBSTR will then return NULL.
    I hope this answers your question.
    If not, post CREATE TABLE and INSERT statements for a little sample data (maybe 5 rows), and the results you want from that data.
    Point out where the query above is producing the wrong results, and explain, using specific examples, how you get those results from the sample data in those places.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

Maybe you are looking for

  • Can't get my 60gb video iPod out of "Restore with iTunes" mode

    I reinstalled Windows the other day and my iPod was still connected to my computer. By the time I noticed this, it said "Connect to computer - use iTunes to restore." I know using "restore" will erase the contents of my iPod, but I don't want to do t

  • Need a simple way to view a professionally made DVD.

    I'm new to Macs (2 weeks) after 13 years in Windows. I have a DVD a professional made for me for our 25th Wedding anniversary. I have been able to play it on my Windows notebook but it freezes after about 40 seconds on the Mac. It starts with a still

  • Automatic clearing & post with clearing

    what is between Automatic clearing & post with clearing?

  • How do i multiply in the grapher app

    how do i multiply an equation in the grapher app????

  • Can't copy and paste

    I recently purchased CS3 and did an update of our website, everything worked okay. Now I return to make changes, I copy/paste onto the pages but this time I get the message ... can not perform that action in this region of the page. Still have not so