Finding substring from string.

I'll have to find substring from another string. Substring to find can be example: CVB and the string can be example ACHGVNB.
Give me some hints about what methods I should use.

Like this:public class Test {
    public static void main (String[] parameters) {
        String sub;
        String text;
        if (parameters.length == 2) {
            sub = parameters[0];
            text = parameters[1];
        } else {
            sub = "levi_h";
            text = "l e v i _ h";
        System.out.println (isSub (sub, text));
    private static boolean isSub (String sub, String text) {
        int s = 0;
        int t = 0;
        while ((s < sub.length ()) && (t < text.length ())) {
            if (sub.charAt (s) == text.charAt (t)) {
                s ++;
            t ++;
        return s == sub.length ();
}Kind regards,
Levi

Similar Messages

  • Find Substring in String in Workflow

    I'm trying to separate the content from GUID with metadata, but I can't find the Find Substring in String function in SharePoint Designer 2013 mentioned on
    MSDN. Can anyone provide guidance? Thanks!

    Its a not a function. It is workflow action under Actions menu in your SPD 2013. 
    You can find that action under the Utility Actions and make sure you have selected All Actions as show in the image above.
    Amit

  • How to extract substring from string... how to find the index?

    suppose i have a string like
    "string1 string2 string3 string4 string....stringK...stringN"
    i would like to extract the substring from string4 to stringK-1
    where stringK and string3 are pre defined strings (ie, i know exactly what stringK and string3 is).
    is there a function to extract the substring from string4 to stringK-1
    or is there a function i can use to determine the index of the end of string4 and the start of stringK?
    thks!

    If your substrings are seperated by a space (or by any other character that isn't used in any of the substrings), you could use something like StringTokenizer.
    If you wanna get real fancy, use the split method of String.

  • How to get substring from string starting from the end of string

    Hi
    How to cut from string:
    $A=C:\ClusterStorage\Volume1\WXP-plwropc300\Virtual Hard Disks\WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
    this substring (name of VHD file): WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
    This script should be universal so the best way to be cut all leters from the end of string $A till get the first mark \
    Thank you for help.
    Tomasz
    Kind Regards Tomasz

    PS > Split-Path 'C:\ClusterStorage\Volume1\WXP-plwropc300\Virtual Hard Disks\WXP-PLWROPC300_EE20E00F-315E-4781
    -A6DE-68497D4189B8.avhdx' -leaf
    WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
    PS >
    That is what "Split-Path" is for:
    ¯\_(ツ)_/¯

  • How to get substring from string using index?

    hi,
    here i am having string ,
    i want the pullareddy from below line ,
    i know how to get from substring.
    but i want to get the above using "index",
    can any help how to do it?
    String str1="janapana,pullareddy, in malaysia";
    jpullareddy

    get the start index with indexAt("pullareddy")
    get the end index with adding the length of the word to the start
    get the char[] of str1 with toCharArray()
    make a new string with the chars from start to end index.

  • To find substr within string

    Hello,
    I have a string (column is normal range) like 70 - 110 mg/dl.
    I wanted to separate 70 and 110.
    For 70 i am using like this
    select substr(normal_range,1,instr(normal_range,'-')-1) from m_parameters where normal_range='70-110 mg/dL'. It works.
    But how to get 110.
    Some rows may also be 110-209 U/L without any space between '-'.I want a query which works for all conditions.
    Conditions are.
    1. 70 - 110 mg/dL
    2. 70-110mg/dL
    3. 70 -110mg/dL
    4. 70- 110mg/dL
    5. 70-110 mg/dL
    thanks
    Swapna

    Hi Swapna,
    Using the old-fashioned SUBSTR and INSTR combination:
    SQL>   with t
      2  as
      3  (
      4  select '0.3 - 1.0 mg/dL' str from dual union all
      5  select '70 - 110 mg/dL' str from dual  union all
      6  select '70-110mg/dL   ' str from dual  union all
      7  select '70 -110mg/dL  ' str from dual  union all
      8  select '70- 110mg/dL  ' str from dual  union all
      9  select '70-110 mg/dL  ' str from dual
    10  )
    11  select trim(substr(str, 1, instr(str, '-') - 1)) num1,
    12         trim(substr(str, instr(str, '-') + 1, instr(str, 'mg') - instr(str, '-') - 1 )) num2
    13    from t;
    NUM1            NUM2
    0.3             1.0
    70              110
    70              110
    70              110
    70              110
    70              110
    6 rows selected.
    SQL>Asif Momen
    http://momendba.blogspot.com

  • Regular expression to get substring from string

    Hi,
    I’m having the following problem:
    SELECT REGEXP_SUBSTR(';first field;ir-second field-02;ir-second field-01; third field','.*ir-(.*)-01.*’)FROM dual
    [\CODE]
    This is the select that I have with a java expression!
    In java I’m able to do find the right expression to retrieve what I want, but I don’t know how to adapt this for oracle!
      In oracle I was trying to do something like this:
    NVL(SUBSTR(REGEXP_SUBSTR(CONCAT(';', list),';ir-[^01;]+'),LENGTH(';ir-')+1,LENGTH(REGEXP_SUBSTR(CONCAT(';',list),';ir-[^01;]+'))), ' ') AS result
    [\CODE]
    But it doesn’t work because “ir” can repeat in other parameters.
    “ir-something-01” only appears once.
    Is it in oracle a logic similar to result groups in oracle?
    best regards,
    Ricardo Tomás

    rctomas wrote:
    Hi,
    In java I’m able to do find the right expression to retrieve what I wantWell, would be nice to tell us what that right expression would be :). Anyway, is this what you are looking for:
    SQL> SELECT REGEXP_SUBSTR(';first field;ir-second field-02;ir-second field-01; third field',';ir-([^;]*)-01')
      2  from dual
      3  /
    REGEXP_SUBSTR(';FIR
    ;ir-second field-01
    SQL> SY.

  • Need a way to extract substring from string in oracle

    Hi all,
    I have one requirement related to extracting string from a paramater.
    suppose the string may like this in various format
    string:= 'This my string <Rid//problem/123456>'
    or
    string:= '<Rid//problem/123456> This my string'
    or
    string:= ' This is <Rid//problem/123456> my string'
    Now my requirement is i need to extract 123456 using pl/sql block.
    is there any way in oracle to get this thing done.
    Thanks n regards
    Laxman

    Hi,
    What version of Oracle ?
    How do you delimit the string to extract ?
    - always between the last / and before the >
    - the last string mande of number ?
    - the first string made of number ?
    Here are 3 possible answers :SQL> with s as (
      2  select 'This my string <Rid//problem/123456>' s from dual
      3  union all select '<Rid//problem/123456> This my string' from dual
      4  union all select ' This is <Rid//problem/123456> my string' from dual
      5  )
      6  select s.s,
      7  regexp_replace(s,'^.*/([0-9]*).*$','\1') r1,
      8  regexp_replace(s,'^[^0-9]*(.*?)[^0-9]*$','\1') r2,
      9  regexp_replace(s,'^.*/(.*?)>.*$','\1') r3
    10  from s ;
    S                                        R1       R2       R3
    This my string <Rid//problem/123456>     123456   123456   123456
    <Rid//problem/123456> This my string     123456   123456   123456
    This is <Rid//problem/123456> my string 123456   123456   123456If you're on 10g or more...
    Of course it also works in PL/SQL :SQL> l
      1  declare
      2  r1 varchar2(50) := 'This my string <Rid//problem/123456>';
      3  r2 varchar2(50) := '<Rid//problem/123456> This my string';
      4  r3 varchar2(50) := ' This is <Rid//problem/123456> my string';
      5  r1b varchar2(50);
      6  r2b varchar2(50);
      7  r3b varchar2(50);
      8  begin
      9  r1b := regexp_replace(r1,'^.*/([0-9]*).*$','\1') ;
    10  r2b := regexp_replace(r2,'^[^0-9]*(.*?)[^0-9]*$','\1') ;
    11  r3b := regexp_replace(r3,'^.*/(.*?)>.*$','\1') ;
    12  dbms_output.put_line('1 : '||r1||' -> '||r1b);
    13  dbms_output.put_line('2 : '||r2||' -> '||r2b);
    14  dbms_output.put_line('3 : '||r3||' -> '||r3b);
    15* end;
    SQL> /
    1 : This my string <Rid//problem/123456> -> 123456
    2 : <Rid//problem/123456> This my string -> 123456
    3 :  This is <Rid//problem/123456> my string -> 123456
    PL/SQL procedure successfully completed.Edited by: Nicosa on Jul 23, 2010 3:22 PM

  • Extract substring from string

    Hi,
    Iu2019m reaching out to the experts in the forum for assistance with resolving a code issue in Universe Designer u2013 itu2019s not producing the expected result.  The following are details, and steps taken:
    Objective: To extract only the characters between #u2019s, i.e. u2013 Smith, John added comments on 12/1/11 V5M#0.25# this is a test.  *NOTE* The characters before AND after the #u2019s varies.
    Database u2013 Oracle 10g
    Field type u2013 CLOB (DBAu2019s will not change) u2013 I created an object u201CDescriptionu201D= DBMS_LOB.SUBSTR("Oracle_Test_Unv". DESC, 4000,1) u2013 I also tried casting as a varchar2 and still the same result.
    Object u2013 Code to extract the characters between #u2019s:
         CASE WHEN @Select(Oracle_Test_Unv\Description) LIKE '%V5M#%#%'
                             THEN DBMS_LOB.SUBSTR(@Select(Oracle_Test_Unv\Description),
                                    DBMS_LOB.INSTR(@Select(Oracle_Test_Unv\Description), '#',1,1)+1,
                                          DBMS_LOB.INSTR(@Select(Oracle_Test_Unv\Description), '#',1,2) -
                                               DBMS_LOB.INSTR(@Select(Oracle_Test_Unv\Description), '#',1,1)-1)
                                                    ELSE '0'
                                                          END
    Current Result:  Smith, John added comments on 12/1/11 V5M#0.25
    Thanks in advance for your help!

    Apologies, I forgot to include the expected result.  Please see below:
    Expected result: 0.25
    Thanks again!

  • Cut Substring from a string

    Hi!
    I have a question
    Can i cut a substring from a string?
    If yes how is possible?
    Can you help me with an example?
    Thanks

    Hi!
    I have a question
    Can i cut a substring from a string?Yes
    If yes how is possible?You shoould read the API for String, there is a method called substring
    Can you help me with an example?You wont need one if you read the API

  • How to get First Occurnece of SubString from any string using SharePoint Designer Workflow in SharePoint Online 2013(Office 365)

    Hello All,
    I am facing Problem in SharePoint Designer Workflow. The Problem is that while replacing some subtstring with Space from a string which contains item like {Test, Test, Test, Test}, It replaces all items.
    Below two line we are using in Workflow.
    Can any body suggest some soultion for Finding first ouucrence of ", " so that we can replace only first value from string not all. When String values are different then getting proper values but if String values are same with comma
    seperated then it replace all values.
    Please some body help and your help will be heighly appriciable.
    Thanks in Advance.
    Thanks,
    Vivek Kumar Pandey   

    Have you tried to use Regular Expressions instead of Replace?
    This post is my own opinion and does not necessarily reflect the opinion or view of Slalom.

  • How to find number from text string??

    Hi All,
    Can you tell me how to find/ fetch number from string?
    is there any function module  for this.?
    for example , I have string like "+++++1000000589+++"
    and I need to fetch the invoice no 1000000589 from the above string..then  How to do that? Letters may come first or number may come first and latter text...
    Regards,
    Mrunal

    You can do like this.
    The below mentioned is code separate material
        DO 18 TIMES.
          LV_C = LV_C + 1.
          LV_C1 = LV_C - 1.
          IF  GW_MATNR-MATNR+LV_C1(1) CN '0,1,2,3,4,5,6,7,8,9' .
            IF ( ( LV_MAT EQ SPACE ) ) ."  and ( lv_prefix eq space ) ) .
              LV_PREFIX = 'X'.
              CONCATENATE GW_TEMP-PREFIX GW_MATNR-MATNR+LV_C1(1) INTO
              GW_TEMP-PREFIX.
            ELSE.
              LV_SUFFIX = 'X'.
              CONCATENATE GW_TEMP-SUFFIX GW_MATNR-MATNR+LV_C1(1) INTO
              GW_TEMP-SUFFIX.
            ENDIF.
          ELSEIF ( ( LV_SUFFIX EQ SPACE ) ) .
            LV_MAT = 'X'.
            CONCATENATE GW_TEMP-MATNR1 GW_MATNR-MATNR+LV_C1(1) INTO
            GW_TEMP-MATNR1.
          ELSEIF ( ( LV_MAT EQ 'X' ) ) .
            CONCATENATE GW_TEMP-SUFFIX GW_MATNR-MATNR+LV_C1(1) INTO
            GW_TEMP-SUFFIX.
          ENDIF.
        ENDDO.

  • How to find the last string value in dynamic object?

    Hi All,
    I am trying to find the last string value in dyanamic objects,Any one have solution for this.
    Ex:
    my data :12347-ebjdone-525-ecgfjf-25236-defdafgdeg
    And i want to show the output is :defdafgdeg
    Any ideas:
    Thanks
    Srini

    For oracle try using oracle function.
    e.g.
    SELECT  reverse(substr(reverse('12347-ebjdone-525-ecgfjf-25236-defdafgdeg'),1,instr(reverse('12347-ebjdone-525-ecgfjf-25236-defdafgdeg'),'-','1'))) from dual
    Object definition might look like:
    reverse(substr(reverse({ObjectName}),1,instr(reverse({ObjectsName}),'-','1')))
    Regards,
    Kuldeep
    Edited by: Kuldeep Chitrakar on Feb 12, 2010 8:12 AM

  • Find out varchar2 string NULL columns and Empty columns

    Hi dev's ,
    my requiremnt is to find out the string columns Names of whose storing NULL values and EMPTY strings. for that i had written below code. it's getting some error.
    SET ECHO OFF;
    SET FEEDBACK OFF;
    SET SERVEROUTPUT ON;
    SET VERIFY OFF;
    SET PAGES 0;
    SET HEAD OFF;
    spool D:\stringnull.csv
    DECLARE
      v_tab_indent NUMBER(5);
      v_col_indent NUMBER(5);
      v_val1       VARCHAR2(20);
      v_val2       VARCHAR2(20);
      v_query1     VARCHAR(500);
      v_query2     VARCHAR(500);
    BEGIN
      --DBMS_OUTPUT.ENABLE(100000);
      SELECT MAX(LENGTH(table_name))+1,MAX(LENGTH(column_name))    +1
      INTO v_tab_indent,v_col_indent
      FROM user_tab_columns
      WHERE data_type='VARCHAR2';
    FOR i IN
      (SELECT table_name,
        column_name
      FROM user_tab_columns
      WHERE data_type IN ('NVARCHAR2', 'CHAR', 'NCHAR', 'VARCHAR2')
      ORDER BY table_name,
        column_name
      LOOP
        v_query1:='SELECT NVL('||i.column_name||',0) AS VAL    
                  FROM '||i.table_name||' where '||i.column_name||' IS NULL';
        v_query2:='SELECT '||i.column_name||' AS VAL    
                  FROM '||i.table_name||' where '||i.column_name||'=''''';
        --dbms_output.put_line(v_query1);
       -- dbms_output.put_line(v_query2);
        EXECUTE immediate v_query1 INTO v_val1;
        EXECUTE immediate v_query2 INTO v_val2;
        dbms_output.put_line (rpad(i.table_name,v_tab_indent,' ')||','||rpad(i.column_name,v_col_indent,' ')||' ,'||v_val1||','||v_val2);
      END LOOP;
    END;
    Spool OFF
    Set echo on
    Set feedback onERROR:
    Error report:
    ORA-01403: no data found
    ORA-06512: at line 31
    01403. 00000 -  "no data found"
    *Cause:   
    *Action:
    set feedback onpls help me on this issue..
    Thanks,

    Example:
    SQL> DECLARE
      2    v_val       VARCHAR2(20);
      3    v_query1     VARCHAR(32767);
      4  BEGIN
      5   FOR i IN (SELECT table_name, column_name FROM user_tab_columns
      6             WHERE data_type IN ('NVARCHAR2', 'CHAR', 'NCHAR', 'VARCHAR2')
      7             ORDER BY table_name, column_name
      8            )
      9   LOOP
    10     v_query1 := 'SELECT count(*) FROM '||i.table_name||' where '||i.column_name||' IS NULL';
    11     EXECUTE immediate v_query1 INTO v_val;
    12     dbms_output.put_line(rpad(i.table_name,30,' ')||' : '||rpad(i.column_name,30,' ')||' : '||v_val);
    13   END LOOP;
    14  END;
    15  /
    CHILD_TAB                      : DESCRIPTION                    : 0
    DEPT                           : DNAME                          : 0
    DEPT                           : LOC                            : 0
    EMP                            : ENAME                          : 0
    EMP                            : JOB                            : 0
    MYEMP_OLD                      : ENAME                          : 0
    MYEMP_OLD                      : JOB                            : 0
    MYNULLS                        : ENAME                          : 0
    MYNULLS                        : JOB                            : 4
    PARENT_TAB                     : DESCRIPTION                    : 0
    T                              : CHAR_VALUE                     : 0
    TABLE1                         : COL1_DESC                      : 0
    PL/SQL procedure successfully completed.

  • Use REGEXP_INSTR to find a text string with space(s) in it

    I am trying to use REGEXP_INSTR to find a text string with space(s) in it.
    (This is in a Function.)
    Let's say ParmIn_Look_For has a value of 'black dog'. I want to see if
    ParmIn_Search_This_String has 'black dog' anywhere in it. But it gives an error
    Syntax error on command line.
    If ParmIn_Look_For is just 'black' or 'dog' it works fine.
    Is there some way to put single quotes/double quotes around ParmIn_Look_For so this will
    look for 'black dog' ??
    Also: If I want to use the option of ignoring white space, is the last parm
    'ix' 'i,x' or what ?
    SELECT
    REGEXP_INSTR(ParmIn_Search_This_String,
    '('||ParmIn_Look_For||')+', 1, 1, 0, 'i')
    INTO Position_Found_In_String
    FROM DUAL;
    Thanks, Wayne

    Maybe something like this ?
    test@ORA10G>
    test@ORA10G> with t as (
      2    select 1 as num, 'this sentence has a black dog in it' as str from dual union all
      3    select 2, 'this sentence does not' from dual union all
      4    select 3, 'yet another dog that is black' from dual union all
      5    select 4, 'yet another black dog' from dual union all
      6    select 5, 'black dogs everywhere...' from dual union all
      7    select 6, 'black dog running after me...' from dual union all
      8    select 7, 'i saw a black dog' from dual)
      9  --
    10  select num, str
    11  from t
    12  where regexp_like(str,'black dog');
           NUM STR
             1 this sentence has a black dog in it
             4 yet another black dog
             5 black dogs everywhere...
             6 black dog running after me...
             7 i saw a black dog
    5 rows selected.
    test@ORA10G>
    test@ORA10G>pratz
    Also, 'x' ignores whitespace characters. Link to doc:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions007.htm#i1048942
    Message was edited by:
    pratz

Maybe you are looking for

  • Adobe Creative cloud for Windows Vista?

    I would like to use my Adobe Creative Cloud subscription (PS & LR) on my Windows Vista Laptop.  Can I use an earlier version that is compatible with this O/S?

  • Icon size in sidebar

    Is it possible to change the icon size in the sidebar of a finder window in Leopard? I am running 10.5.3 and the icons are much smaller than in 10.4

  • Calling a servlet from java

    How to call a servlet from java? your help is greatly appreciated..

  • ESS 50.4 and MSS 60.1.20 for R/3 4.7 using EP7.0 and external ITS 6.20

    SAP@WEB studio Hi All, we are implementing ESS 50.4 and MSS 60.1.20 for R/3 4.7 using EP7.0 and external ITS 6.20. 1). first of all is this landscape possible ? 2). If it is possible then do i need SAP@WEB studio along with the external ITS ? 3). onc

  • SLD  export

    Hi there, We are building a parallel landscape  for PI and would like to have an exact copy of our existing Dev system with a different SID. The method we are using is fresh installation with export/import  of content from source to target. I need so