Check if a string contains another string

can anybody help?
String st="DC";
how can i check if another string contains "DC" or not?

How bout
if(someString.indexOf(st) != -1) {
     //someString contains st at some point
}

Similar Messages

  • Replacing a special character in a string with another string

    Hi
    I need to replace a special character in a string with another string.
    Say there is a string -  "abc's def's are alphabets"
    and i need to replace all the ' (apostrophe) with &apos& ..which should look like as below
    "abc&apos&s def&apos&s are alphabets" .
    Kindly let me know how this requirement can be met.
    Regards
    Sukumari

    REPLACE
    Syntax Forms
    Pattern-based replacement
    1. REPLACE [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF]
    pattern
              IN [section_of] dobj WITH new
              [IN {BYTE|CHARACTER} MODE]
              [{RESPECTING|IGNORING} CASE]
              [REPLACEMENT COUNT rcnt]
              { {[REPLACEMENT OFFSET roff]
                 [REPLACEMENT LENGTH rlen]}
              | [RESULTS result_tab|result_wa] }.
    Position-based replacement
    2. REPLACE SECTION [OFFSET off] [LENGTH len] OF dobj WITH new
                      [IN {BYTE|CHARACTER} MODE].
    Effect
    This statement replaces characters or bytes of the variable dobj by characters or bytes of the data object new. Here, position-based and pattern-based replacement are possible.
    When the replacement is executed, an interim result without a length limit is implicitly generated and the interim result is transferred to the data object dobj. If the length of the interim result is longer than the length of dobj, the data is cut off on the right in the case of data objects of fixed length. If the length of the interim result is shorter than the length of dobj, data objects of fixed length are filled to the right with blanks or hexadecimal zeroes. Data objects of variable length are adjusted. If data is cut off to the right when the interim result is assigned, sy-subrc is set to 2.
    In the case of character string processing, the closing spaces are taken into account for data objects dobj of fixed length; they are not taken into account in the case of new.
    System fields
    sy-subrc Meaning
    0 The specified section or subsequence was replaced by the content of new and the result is available in full in dobj.
    2 The specified section or subsequence was replaced in dobj by the contents of new and the result of the replacement was cut off to the right.
    4 The subsequence in sub_string was not found in dobj in the pattern-based search.
    8 The data objects sub_string and new contain double-byte characters that cannot be interpreted.
    Note
    These forms of the statement REPLACE replace the following obsolete form:
    REPLACE sub_string WITH
    Syntax
    REPLACE sub_string WITH new INTO dobj
            [IN {BYTE|CHARACTER} MODE]
            [LENGTH len].
    Extras:
    1. ... IN {BYTE|CHARACTER} MODE
    2. ... LENGTH len
    Effect
    This statement searches through a byte string or character string dobj for the subsequence specified in sub_string and replaces the first byte or character string in dobj that matches sub_string with the contents of the data object new.
    The memory areas of sub_string and new must not overlap, otherwise the result is undefined. If sub_string is an empty string, the point before the first character or byte of the search area is found and the content of new is inserted before the first character.
    During character string processing, the closing blank is considered for data objects dobj, sub_string and new of type c, d, n or t.
    System Fields
    sy-subrc Meaning
    0 The subsequence in sub_string was replaced in the target field dobj with the content of new.
    4 The subsequence in sub_string could not be replaced in the target field dobj with the contents of new.
    Note
    This variant of the statement REPLACE will be replaced, beginning with Release 6.10, with a new variant.
    Addition 1
    ... IN {BYTE|CHARACTER} MODE
    Effect
    The optional addition IN {BYTE|CHARACTER} MODE determines whether byte or character string processing will be executed. If the addition is not specified, character string processing is executed. Depending on the processing type, the data objects sub_string, new, and dobj must be byte or character type.
    Addition 2
    ... LENGTH len
    Effect
    If the addition LENGTH is not specified, all the data objects involved are evaluated in their entire length. If the addition LENGTH is specified, only the first len bytes or characters of sub_string are used for the search. For len, a data object of the type i is expected.
    If the length of the interim result is longer than the length of dobj, data objects of fixed length will be cut off to the right. If the length of the interim result is shorter than the length of dobj, data objects of fixed length are filled to the right with blanks or with hexadecimal 0. Data objects of variable length are adapted.
    Example
    After the replacements, text1 contains the complete content "I should know that you know", while text2 has the cut-off content "I should know that".
    DATA:   text1      TYPE string       VALUE 'I know you know',
            text2(18)  TYPE c LENGTH 18  VALUE 'I know you know',
            sub_string TYPE string       VALUE 'know',
            new        TYPE string       VALUE 'should know that'.
    REPLACE sub_string WITH new INTO text1.
    REPLACE sub_string WITH new INTO text2.

  • I need to append a string to another string

    I'm working with some inherited code, I'm a Colf Fusion
    novice myself, and I'm trying to make this order form display the
    correct data. The problem is a lot of data in the database is
    missing. Description in the QStockDB query can contain a lot of
    stuff. For our full color work the text "4/0", "4/BLACK", and "4/4"
    are consistent so I'm changing the newitem (I know, not very
    descriptive but it's not my code) to CMYK Printing.
    <cfif #QStockDB.description# contains "4/0"><cfset
    newitem = "CMYK Printing"></cfif>
    <cfif #QStockDB.description# contains
    "4/4/BLACK"><cfset newitem = "CMYK Printing"></cfif>
    <cfif #QStockDB.description# contains "4/4"><cfset
    newitem = "CMYK Printing"></cfif>
    I want to then go back through description and compare it
    more to add more description. For instance with this:
    <cfif #QStockDB.description# contains "12 pt"><cfset
    newitem = newitem + " - BC"></cfif>
    I know that the job is a business card. So I want to append
    the newitem variable with " - BC". Likewise:
    <cfif #QStockDB.description# contains
    "catalog"><cfset newitem = newitem + " - Catalog
    Sheets"></cfif>
    displays CMYK Printing - Catalog Sheets. Or, it should... or,
    more precisely, I want it to. :)
    How do I append a string to another string?

    + is the addiion operator and works with numbers. Because
    your string is a ...well, string... you need to use an ampersand.
    Thus, instead of:
    <cfif #QStockDB.description# contains
    "catalog"><cfset newitem = newitem + " - Catalog
    Sheets"></cfif>
    Use...
    <cfif #QStockDB.description# contains
    "catalog"><cfset newitem = newitem & " - Catalog
    Sheets"></cfif>
    <cfoutput>#newitem#</cfoutput>
    At least I think that will work - haven't tested it
    though.

  • Replace a string with another string in a file

    I have to replace a string with another string. Say for example in a html file it got a line like,
    <a href="##"></a>
    now i want to replace this ## with the full derived path like
    "c;\\sample folder\\sample subfolder\\samplefile.html"
    can someone help me to do this?
    pls tell me from the file opening till closing the file.

    I have to replace a string with another string. Say
    for example in a html file it got a line like,
    <a href="##"></a>
    now i want to replace this ## with the full derived
    path like
    "c;\\sample folder\\samplesubfolder\\samplefile.html"
    can someone help me to do this?
    pls tell me from the file opening till closing the
    file.
    public class Buckel {
      final static String CONST = "c:\\sample folder\\samplesubfolder\\samplefile.html";
      public Buckel() {
      public static void main ( String[] argv )  throws Exception {
        int    idx = 0;
        String in  = "<a href=\"##\"></a>",   // We'll imagine this just gets here somehow. If it's on the i/p file then take the '\' out B4 and aft the '##'.
               out = "";
        idx = in.indexOf( "##" );
        if ( idx > 0 ) {
          out = in.substring( 0, idx ) + CONST + in.substring( idx+=2, in.length() );
        System.out.println( out );
    }

  • One string contains another. Function?

    Which function can i use in order to find out if String a is contained inside String b?

    Which function can i use in order to find out if
    String a is contained inside String b?Read the API. It is your friend.
    http://java.sun.com/j2se/1.4.2/docs/api/index.html

  • How can I substitute a string with another string in a file

    I have a file. I have a substitute a keyword with another string in all the occurences of a file. How can I do this?

    I'm gonna give you the benifit of the doubt and assume you didn't mean to double post your question.
    As to substitute a keyword with a string one way is to read in the file and run it through a StreamTokenizer class to break it into words. Pull one word at a time, check it, and stick it into a StringBuffer. Once your done with the file overwrite it with what is in the StringBuffer.
    Another way might be to use the RandomAccessFile class, but I'm not really familiar with that because I hardly ever use it.

  • Find occurences of a string inside another string

    How can I loop through String text for occurences of String lineSeparator, and replace each occurence with String lineShift?
    String lineSeparator = "<line_separator/>";
    String lineShift = "\n";
    String text = "This<line_separator/>is<line_separator/>a<line_separator/>test<line_separator/>";Do I have to use Patterns or something?

    String lineSeparator = "<line_separator/>";
    String lineShift = "\n";
    String text = "This<line_separator/>is<line_separator/>a<line_separator/>test<line_separator/>";
    String modified = text.replaceAll(lineSeparator, lineShift);
    System.out.println(modified);

  • Copyieng some charecters from string  to another string

    hi all,
    its urgent.
    there r two strings
    A  =  'IEQ0100'.
    AA  = ' '.
    and i want to copy only last 4 charecters from String A to String AA.
    could u please help me
    thx in advance..........
    Sunil

    l =strlen(a).
    d = l - 4.
    aa1(4) = ad(4).
    REPORT zex35 .
    DATA : a(7) VALUE 'IEQ0100',
           aa(7) VALUE ' '.
    DATA : l TYPE i,
           d TYPE i.
    l = strlen( a ).
    d = l - 4.
    aa1(4) = ad(4).
    WRITE : / aa.
    If u dont want first character space in aa then change the below statement
    aa1(4) = ad(4).
    to
    aa0(4) = ad(4)
    or
    aa = a+d(4).

  • Checking for an element in a string from another string

    Hi Guru's,
    I have 2 comma seperated strings. Say like this.
    a VARCHAR2(100) := '1,2,3,4,5,6,7,8,9,10';
    b VARCHAR2(100) := '2,6,9';
    My requirement is like I want to check the string a, whether it has any of the element in b. I am trying to use the regular expression. But I was not able to do it.
    Kindly help me.
    Regards,
    VJ

    SQL> var cur refcursor
    SQL> declare
       a              varchar2 (100) := '1,2,3,4,5,6,7,8,9,10';
       b              varchar2 (100) := '2,6,9';
    begin
       open :cur for 'select column_value common
            from table (sys.dbms_debug_vc2coll (' || a || ') multiset intersect sys.dbms_debug_vc2coll (' || b || '))';
    end;
    PL/SQL procedure successfully completed.
    SQL> print
    COMMON                                                                                                                           
    2                                                                                                                                
    6                                                                                                                                
    9                                                                                                                                
    3 rows selected.

  • How to find a string inside another String variable

    Hi,
    I need to find whether a string is available in a String of varying length.
    i.e., i want to know string "access" is available in a String variable( may have values like "microsoft access 2000 bla bla bla .." or "bla bla access microsoft").
    so, i dont know the starting point of the word 'access' in the String variable.
    Pls help me in doing this.
    Thanks in advance,
    Rao

    Check the API documentation for this method:
    "int indexOf(String str)
    Returns the index within this string of the first occurrence of the specified substring."

  • Take and delete a String from another String

    I have original input string= 111100001111
    I need to Take for example the least 4 bits .... Output= 1111
    and to be removed from the original input string so the original input string= 11110000 
    I am trying to make a generic one but the point is that I can not delete subset that I take from the original input String.  
    How can I take and delete from a string in the same time? 
    Solved!
    Go to Solution.

    Something like this?
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Split String.png ‏13 KB

  • Replaces all occurnces of one String with another String in a given source

    Hi all I had found that there is a lot of interest int this topic. there is a little piece of code that I wrote for myself recently, so I fgigured that it might be helpful for some...
    This method will scan through a string "source", find all of the occurances of a String "before" and replace them with the "after".
    Enjoy :-)
    public static String replace(String source, String before, String after)
    StringBuffer sb = new StringBuffer(source);
    int startpos = source.indexOf(before);
    int endpos = startpos + before.length();
    int i = startpos;
    while( i > -1 )
         if( startpos > -1 && endpos <= source.length() )
         source = sb.replace(startpos, endpos, after).toString();
         int lastReplace = source.lastIndexOf(after) + after.length();
         if(lastReplace <= source.length())
              startpos = source.substring(lastReplace, source.length() ).indexOf(before);
                   endpos = startpos + before.length();
                   i = startpos;
         else
              i = source.length();
         else
              i = -1;
    return source;
    Oh yeah if you want, you can visit my site http://www.infobrokery.com it is where this code is used to replace the text URL with html.

    Since 1.4 the String class has a replaceAll method ...

  • How to copy one string to another string?

    suppose you have 2 local strings  strA, strB.  can you show me an expression that copy the content of strA to strB?
    Thanks

    Locals.strB = Locals.strA

  • How to replace part of a String with another String :s ?

    Got a String
    " Team_1/Team_2/Team_3/ "
    And I want to be able to rename part of the string (they are seperated by '/'), for example I want to rename "Team_3" to "Team C", and "Team_1" to "Team A" while retaining the '/' character how would I do this?
    I have tried using String.replace(oldValue, newValue); but this doesnt work, any ideas?

    What do you mean that it doesn't work? You do know that the method returns the modified string? The actual string that you invoke the method on is not altered.
    /Kaj

  • Extracting string from another string

    Hi,
    I have a problem that I am having difficulty solving, if anyone has any bright ideas it would be a great help.
    I have a description field in one of my tables and the description would read something like
    my website can be found at www.mywebsite.com, and it is great
    I want to be able to extract the web address from this sentance, so the result would be
    www.mywebsite.com
    I can do this specific for one sentance but I can't find a way to do it for many different sentances.
    cheers in advance

    r u expecting this..?
    select substr('my web site is www.abcd.com and u can...',instr('my web site is www.abcd.com and u can...','www.',1),instr(substr('my web site is www.abcd.com and u can...',instr('my web site is www.abcd.com and u can...','www.',1)),' ',1)) from dual;

Maybe you are looking for

  • Please provide the abap code for below requirement

    note: if the user exit is not suitable please provide the suitable user exit and code 1   Business requirement       In order to update the postings and tracking on Buffer Account postings the User Exists need to be modified and extended where possib

  • Export Warning

    How can I keep the design of my slide, and avoid this message when exporting to powerpoint. I have to save it as powerpoint because the computer im presenting the presentation to in class has powerpoint. Export Warning - Masking with shapes isn't sup

  • Maximum size to reference text fields in report painter

    I have created a library for report painter but reference text fields were not transfered because of their size exceed 24 character long. is there some SAP procedure to extend this size at the moment we are creating the library?  Thanks in advance fo

  • Bad load arguments supplied when starting up the Reports Server

    Dear All, In report60\server\<filename>.ora Following were the contents : maxconnect=20 cachedir="d:\Oracle\806\REPORT60\server\cache" cachesize=50 minengine=0 initengine=0 maxengine=1 maxidle=30 security=1 englife=50 We chnaged it to maxconnect=20 c

  • How Program RCPMAU03 or FM CX_IN_HOUSE_PRODUCTION_TIME calculates Prod time

    Hi All, FM CX_IN_HOUSE_PRODUCTION_TIME is used in Program RCPMAU03 which is used for Material Master Update from transaction CA47 or CA47N. I want to know how this FM calculates Processing(BEARZ) and InterOperation(MARC-TRANZ) time. Thanks in advance