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);

Similar Messages

  • How to find the number of occurence of a string

    String str="The AR tech seeks experienced candidates in java,jsp. The candidates should have atleast 1 year of experience in the specified skills.";
    here i need to find the number of occurence of the string "experience".
    how to find it out?

    String str="The AR tech seeks experienced candidates in java,jsp. The candidates should have atleast 1 year of experience in the specified skills.";
    String findStr = "experience";
    int count = 0;
    int index = 0;
    while(index != -1) {
    index = str.indexOf(findStr, (count == 0 ? 0 : index + findStr.length()));
    if(index != -1) {
    count++;

  • Query engine : Can not find DSN in Connection String

    DearSir/Madam,
    Opearating System Windows 7 Professional(32-bit).
    I am using Application, which is developed : Visual basic 6.0(32-bit), Report Writer : Crystal Report 9.2.693(32-bit) and database: Oracle 9.2.0.10(32-bit).
    ODBC Data source : System DSN created and Connection established (Based on Driver : CR ORACLE ODBC Driver 4.10 (cror818.dll))
    In windows 7 environment Data Base connectivity and data fetching also wroking fine.
    My problem is while running reports it display error as "Query engine : Can not find DSN in Connection String"
    I want run time reports.
    For your kind information, at the same time in Windows XP Professional there is no problem found and working fine.
    Kindly help me.
    Thanks and regards,
    Swarup

    Crystal Reports 9.x is not supported on Win 7. See the following wiki:
    http://wiki.sdn.sap.com/wiki/x/b4JiAw
    - Ludek

  • [Forum FAQ] How to find and replace text strings in the shapes in Excel using Windows PowerShell

    Windows PowerShell is a powerful command tool and we can use it for management and operations. In this article we introduce the detailed steps to use Windows PowerShell to find and replace test string in the
    shapes in Excel Object.
    Since the Excel.Application
    is available for representing the entire Microsoft Excel application, we can invoke the relevant Properties and Methods to help us to
    interact with Excel document.
    The figure below is an excel file:
    Figure 1.
    You can use the PowerShell script below to list the text in the shapes and replace the text string to “text”:
    $text = “text1”,”text2”,”text3”,”text3”
    $Excel 
    = New-Object -ComObject Excel.Application
    $Excel.visible = $true
    $Workbook 
    = $Excel.workbooks.open("d:\shape.xlsx")      
    #Open the excel file
    $Worksheet 
    = $Workbook.Worksheets.Item("shapes")       
    #Open the worksheet named "shapes"
    $shape = $Worksheet.Shapes      
    # Get all the shapes
    $i=0      
    # This number is used to replace the text in sequence as the variable “$text”
    Foreach ($sh in $shape){
    $sh.TextFrame.Characters().text  
    # Get the textbox in the shape
    $sh.TextFrame.Characters().text = 
    $text[$i++]       
    #Change the value of the textbox in the shape one by one
    $WorkBook.Save()              
    #Save workbook in excel
    $WorkBook.Close()             
    #Close workbook in excel
    [void]$excel.quit()           
    #Quit Excel
    Before invoking the methods and properties, we can use the cmdlet “Get-Member” to list the available methods.
    Besides, we can also find the documents about these methods and properties in MSDN:
    Workbook.Worksheets Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff835542(v=office.15).aspx
    Worksheet.Shapes Property:
    http://msdn.microsoft.com/en-us/library/office/ff821817(v=office.15).aspx
    Shape.TextFrame Property:
    http://msdn.microsoft.com/en-us/library/office/ff839162(v=office.15).aspx
    TextFrame.Characters Method (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff195027(v=office.15).aspx
    Characters.Text Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff838596(v=office.15).aspx
    After running the script above, we can see the changes in the figure below:
    Figure 2.
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thank you for the information, but does this thread really need to be stuck to the top of the forum?
    If there must be a sticky, I'd rather see a link to a page on the wiki that has links to all of these ForumFAQ posts.
    EDIT: I see this is no longer stuck to the top of the forum, thank you.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Find and Replace text string in HTML

    Opps... I hope this forum is not just for Outlook. My Html files reside on my hard-drive. I am looking for VBA code to open specified file names ####File.html and then find and replace text strings within the html for example "####Name" replaced
    with "YYYYY"
    I drive the "####File.html" names and the find and replace text strings from an Excel sheet. I am an artist and this Sub would give me time to paint instead of find and replace text. Thank you!
    [email protected]

    Hello Phil,
    The current forum is for developers and Outlook related programming questions. That's why I'd suggest hiring anybody for developing the code for you. You may find freelancers, for example. Try googling for any freelance-related web sites and asking such
    questions there.
    If you decide to develop an Outlook macro on your own, the
    Getting Started with VBA in Outlook 2010 article is a good place to start from.

  • How to find out if a string is all alphabets

    Hi,
    How can I find out if a string contains all alphabets? Please help. Thanks.

    Hi,
    How can I find out if a string contains all
    all alphabets? Please help. Thanks. I am not sure if there's easier way. But this code should do what you want:
    boolean bAlpha = true;
    for (int i=0; i<str.length; i++)
    if (!Character.isLetter(str.charAt(i))){
    bAlpha = false;
    break;
    //bAlpha is true if str contains only alphabets.

  • Newbie question: cannot find symbol symbol: class STRING

    I've just decided to teach myself some java, and on my first try something's going wrong and I don't know what it is.
    I'm currently doing this tutorial: http://java.sun.com/docs/books/tutorial/uiswing/learn/example1.html
    and everything is good until I try to compile it and I get this error in the cmd
    HelloWorldSwing.java:30: cannot find symbol
    cannot find symbol
    symbol: class STRING
    everything has been written verbatim from the tutorial, including "import javax.swing.*;"
    What's wrong with it and how do I fix it?

    Hi,
    I saw the coding that You had given a link in your post. Change the following
        public static void main(String[] args) {bye for now
    sat

  • How to count a occurence of a string in file

    import java.util.*;
    import java.io.*;
    class Count
    public static void main(String args[ ] )throws Exception
         FileReader fr=new FileReader("d:\\compfetch\\clean\\first.txt");
         BufferedReader br=new BufferedReader(fr);
         StringBuffer sb=new StringBuffer();
         while((s=br.readLine())!=null)
              sb.append(s);
         s=sb.toString();
    Vector v= new Vector();
         v.addElement("job");
         v.addElement("jobs");
         v.addElement("career");
         v.addElement("careers");
         v.addElement("vacancy");
         v.addElement("vacancies");
         v.addElement("opportunity");
         v.addElement("openings");
         v.addElement("posting");
         v.addElement("postings");
         v.addElement("opportunities");
         v.addElement("placement");
         v.addElement("placements");
         v.addElement("job");
         v.addElement("job");
         Enumeration vEnum=v.elements();
         while(vEnum.hasMoreElements())
              System.out.println(vEnum.nextElement());
    I need to count the occurence of each string given in the vector from the text file.I have the file and the vector.How do i compare the vector and textfile ,so that i can count the occurence of eachString in the vector with the text file.The text file may contain any of the words given in the vector.If found ,a count shld be made for each string .
    regards,
    koel

    Try this code:
    import java.util.*;
    import java.io.*;
    class Count
    public static void main(String args[ ] )throws Exception
         FileReader     fr = new FileReader("c.c");
         BufferedReader br = new BufferedReader(fr);
         StringBuffer   sb = new StringBuffer();
         String         s;
         while((s=br.readLine())!=null)
              sb.append(s);
         s=sb.toString();
         Vector v= new Vector();
         v.addElement("job");
         v.addElement("jobs");
         v.addElement("career");
         v.addElement("careers");
         v.addElement("vacancy");
         v.addElement("vacancies");
         v.addElement("opportunity");
         v.addElement("openings");
         v.addElement("posting");
         v.addElement("postings");
         v.addElement("opportunities");
         v.addElement("placement");
         v.addElement("placements");
         Enumeration vEnum=v.elements();
         while(vEnum.hasMoreElements())
              String l = (String)vEnum.nextElement();
              int    a = 0;
              int    p = s.indexOf(l,a);
              int    c = 0;
              while (p != -1)
                   c = c + 1;
                   a = a + l.length() + p;
                   p = s.indexOf(l,a);
              System.out.println(l+"  "+c);
    }

  • How to find and replace any string between " "

    Hi everyone,
    Here my sample
    String szTest;
    szTest = "Yellow banana";
    szTest = "Blue monkey";
    szTest = "Red mango";
    szTest is only needed when it's in testing progress. Now I want to put all of that in the /*comment*/ so the released program won't run those code any more (but still keep szTest so I can use it for future develop testing).
    So Here what I want after using the Find and Replace Box:
    //String szTest; //Manual
    /*szTest = "Yellow banana";*/ //use find and replace
    /*szTest = "Blue monkey";*/ //use find and replace
    /*szTest = "Red mango";*/ //use find and replace
    I think I can do this with Regular expressions or Wildcards. But I don't know how to find and replace any string between " and ".
    Find: szTest = " ??Any string?? ";
    Replace with: /*szTest = " ??Any string?? ";*/
    Thanks for reading.

    Hi Nathan.j.Smith,
    Based on your issue, I suggest you can try the Joel's suggestion check your issue again. In addition, I find a MSDN document about how to use the Regex.Replace Method to match a regular expression pattern with a specified replacement string,
    maybe you will get some useful message.
    https://msdn.microsoft.com/en-us/library/xwewhkd1(v=vs.110).aspx
    If the above suggestion still could not provide you, could you please tell me what language you use to create the program for finding and replace any string using regular expression so that we will find the correct programming develop forum to support this
    issue?
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Finding number in a string

    I am trying to find a number in a string from my database to replace it.  Here is my funciton:
    function findUserID($friendsString, $userToFind){
              echo $friendsString . " " . $userToFind;
              $pos = strpos($friendsString,$userToFind);
              if($pos){
                        return true;
              return false;
    it returns "25,29 25".  How can it not find 25 in that string?

    I understand that it starts at 0.  it should still work.  i had it working before.  i must've changed something. 
    here is my code for passing to the function:
    $query = mysql_query("SELECT friends, pendingFriendRequest
    FROM members
    WHERE username = '$userID'");
    if (mysql_affected_rows() > 0) {
              $row = mysql_fetch_array($query) or die(mysql_error());
              $friends = $row['friends'];
              $pendingFriends = $row['pendingFriendRequest'];
    // If the user exists in the waiting list, then
    //continue (we must confirm that they are first by checking the DB
    $test = findUserID($pendingFriends, "25");
    if($test){
              // If they are, then continue to add them
              $test = confirmFriend($pendingFriends, "25");
              if($test) {
                        echo "<br />You have confirmed " . findUserName(24) . "as a friend.";
              } else {
                        echo "<br />Error: Please try again, or contact us.";
    } else {
              echo "<br />Error: You either have this person as a friend already, or there was an internal error.";

  • Where can I find the appropriate text string for China Time zone?

    Hi,
    Where can I find the appropriate text string for China Time zone?

    Hi,
    The following timezone strings are supported in Oracle8i 8.1.7:
    AST, ADT: Atlantic Standard or Daylight Time
    BST, BDT: Bering Standard or Daylight Time
    CST, CDT: Central Standard or Daylight Time
    EST, EDT: Eastern Standard or Daylight Time
    GMT: Greenwich Mean Time
    HST, HDT: Alaska-Hawaii Standard Time or Daylight Time.
    MST, MDT: Mountain Standard or Daylight Time
    NST: Newfoundland Standard Time
    PST, PDT: Pacific Standard or Daylight Time
    YST, YDT: Yukon Standard or Daylight Time
    Since your's isn't one of these, I'm hoping this is in reference to the Web Agent's ORDWEBUTL package, in which case, you can use an offset from GMT instead. For example, here in New Hampshire, USA, we are 5 hours behind GMT, so the offset would be -5, while in France, it would be +1 as they are one hour in front of GMT. According to my Windows clock, Beijing is GMT +8. Of course, you'll have to figure daylight-savings time into the equation, if you have to deal with such changes.
    Regards,
    Simon
    null

  • 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.

  • Finding md5 of a string in java

    can any one tell me how to find md5 of a string in java

    md5 is dead. stop using it.There are still cases where it is very useful.
    Have the contents of my file changed since the last time its digest was taken and stored?
    * MD5 implementation
    * written Santeri Paavolainen, Helsinki Finland 1996
    * (c) Santeri Paavolainen, Helsinki Finland 1996
    * modifications Copyright (C) 2002-2004 Stephen Ostermiller
    * http://ostermiller.org/contact.pl?regarding=Java+Utilities
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 2 of the License, or
    * (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    * See COPYING.TXT for details.
    * The original work by Santeri Paavolainen can be found at
    * http://www.helsinki.fi/~sjpaavol/programs/md5/
    */

  • Finding first numeric in string

    Hi,
    I am trying to find a way I can find the first numeric in a string.
    This works but I have to do it 10 times:
    String vtemp = vdoc.indexOf('1');Example of data:
    AB123
    CDE456
    ABCD789I am trying to find a way to do something like: indexOf(any number); So I can get the result in one line of code.
    Thanks for any help

    Hi GaryJSF,
    You have to convert your string into an array of characters and for each character, check if it's a digit until you find the first one :
    String str = "ABC123";
    char[] crs = str.toCharArray();
    for (int i = 0; i < crs.length; i++) {
        if (Character(crs).isDigit()) {
    System.out.println("first index = " + i);
    break;

  • How to use one hash table inside another hash table

    Hi everyone,
    Any example of hash table inside another hash table.
    Can one here help me how to write one hash table inside another with repeating keys for the first hash table.
    Thanks,
    kanty.

    Do you mean you want the 'value' entries in a hash table to themselves be hash tables? Easy but this often indicates a design flaw.
    Hashtable<String,<Hashtable<String,Value>> fred = new Hashtable<String,<Hashtable<String,Value>> ();But what do you mean by "with repeating keys for the first hash table"?
    Edited by: sabre150 on Jul 2, 2010 10:11 PM
    Looks like you have already handled the declaration side in your other thread. I suspect you should be writing your own beans that hold the information and these beans would then be stored in a Map. The problem I have is that your description is too vague so I can't be certain.

Maybe you are looking for

  • Recordset Per message

    Hi Group, I am using Record ser per message to split my large volume messages,but in my input I have one header,unbounded items,one tailor when I am using record set message it is splitting items and getting error in the MONI that Header target not a

  • Import more than 1 dump file

    Kindly some one help me , how to specify more than 1 dump file in the para file. I know how to spcify one dump file in the parfile. I dont know how to specify 2 dump file to load as my export produces 2 dump files as the limit of file size.

  • "an error has occured" while downloading OS X Mountain Lion

    I have purchased the OS X Mountain Lion and it downloaded about half way on my macbook then stopped. Now when i go into the app store under purchased it says "an error has occured" and there is no option to resume the download, how can i get it to do

  • Email server setup

    I have setup DNS and an mx record; I've tested it and all is fine.  I am now setting up the mail server, what I am interested in is how the server knows which emails are for which user.  Is it just via the email prefix and the short name of the user.

  • My droid incredible 2 screen went black.

    My screen went black. Help!!!