Text, Searching, and Replacing

After looking at the API's for String, StringBuffer, and StringTokenizer I am not sure how to accomplish my task. I have a StringBuffer that contains the contents of a file. I want to search in that StringBuffer for text '<servlet-name>Name</servlet-name>', then continue searching to the next occurence of '</servlet>', then insert several lines of text before '</servlet>'. The text I am searching is not always in the same position in each file I am reading. I sure would appreciate a point in the right direction.
Thanks much!
Zach

Since you're working with an XML file the cleanest but disruptive and heavyweight solution would be to parse the file into a DOM tree, modify the tree and render it back out to a file. Let me know if you want to discuss this approach further.
If you prefer to proceed with text-only modification, you could do the following:
1 Read the file into a StringBuffer
2 Get a String view using StringBuffer.toString()
3 Use String.indexOf() twice to find the right place to insert your additional lines
4 Use StringBuffer.insert() to add your text
5 Write the StringBuffer back to a file.

Similar Messages

  • Search and Replace text in file using PowerShell

    I want to schedule a script in PowerShell to search a directory for an XML file for a particular text string and replace it with a different text string and then save the file with the same name, the name of the file
    will change each time the script is run on a daily basis. There will only be one XML file in the location when the scheduled script is run.
    I have never used PowerShell but am familiar with batch file commands, can anyone please help!!
    KevinS

    Hi Kevin,
    I’m writing to just check in to see if the suggestions were
    helpful. If you need further help, please feel free to reply this post directly so we will be notified to follow it up.
    If you have any feedback on our support, please
    click here.
    Best Regards,
    Anna
    TechNet Community Support

  • Search and Replace text

    Apologies for what is no doubt a simple question - I'm trying to help out IT and I'm not a programmer, although maybe one day...
    Anyway, I'm going to need to read a text file, and search for a string in that text file and replace it.  I see "replace" as a function but I'm not familiar with how to use it.  Poking around I found <cffile action=append> and used that to add a line to a text document.  (Just a notepad .txt)
    Ultimately I'll need to unzip a folder, search and replace the string in a specific file in there, and then re-zip the file, but we'll get to that later.  I managed to unzip a folder already, that's easy enough.  Putting it all together is my current challenge.
    I'm using ColdFusion Builder 2.0
    Thanks for any help you guys can give.

    file.txt: Contains several lines that all say "All Work And No Play Makes Jack A Dull Boy".
    <cffile action="read" file="C:\file.txt" variable="myFile">
    <cfset myFile = Replace(myFile,"Dull","Bored","all")>
    <cffile action="write" file="C:\file.txt" output="#myFile#" addnewline="no" fixnewline="no">
    <cffile action="read" file="C:\file.txt" variable="myNewFile">
    <cfoutput>#myNewFile#</cfoutput>
    ^_^

  • In Pages, how to search and replace text involving invisible characters?

    In Pages documents, how to search and replace text involving invisible characters, colors and font sizes—a task which is so easy in Mircosoft Word?

    I read that an older version of Pages allowed users to enter special characters in the search/replace fields, but this did not work for me.
    Here: http://www.macworld.com/article/1156533/pagesspecialcharacters.html
    I still am looking for a way to do this.

  • Search and replace selected text

    Is there a way to have search and replace only look in selected text and not the whole document? My problem is, e.g., in a table, the author used x's instead of checkmarks (our preferred). In Word I could highlight the text, search for X to replace with T (which I then set as WP Iconic font to show the T as a checkmark), then tell it to change all, and the x's would be corrected. I can't find that same command in InDesign and, therefore, have to go through each table and replace the X with a T.
    Also, is there a way to assign the first rows of an existing table as header (repeating) rows? I know how to tell it I want two header rows, but it creates new rows and I have to copy my text into the "header" rows.
    Thanks for all the help I get here!

    Both are actually easy to find in the online help ...

  • Using a variable in a Powershell search and replace string

    Hi
    a couple of days ago I posted a question about doing a search and replace with wildcards
    Search and repalce with Widcards
    I got a swift and very helpful answer but now I need to build on it.
    In a text file I wanted to replace all the text between two defined words.  the script I got was this
    $text = 'Some Server this bit of text varies Language stuff'
    $text -replace '(.*Server) .+? (Language.*)','$1 it will always say this $2'
    It works great but now I want to replace "it will always say this" with a variable and I can't figure out the correct grammar to make this happen.
    Can anyone help??
    Thanks
    Alex

    Here's one way:
    $replace = 'it will aways say this'if ( $text -match '(.*Server) .+? (Language.*)' )
    { "{0} $Replace {1}" -f $matches[1,2] }
    else { $text }
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • HTML character entities problem in saved regex search and replace query

    I have a many search and replace regular expression queries (.dwr files) that I have saved. I have a problem specifically with saved queries that contain HTML entities such as "& nbsp ; " or "& shy ;" (spaces added otherwise code doesn't render in browser). For example if I use the following search:
    ([\d]{3}& shy ;[\d]{3}& shy ;[\d]{4}|[\d]{3}& nbsp ;[\d]{3}& nbsp ;[\d]{4})
    (which searches for numbers in the 888-555-1234 or 888 555 1234 formats)
    This will work fine if I manually enter it into the search text area. However if I save it to file and reload it, it will no longer work because the &shy; and   characters are now displayed as " " (space) and "-"(shy) rendering the saved query useless as it's no longer searching for the code. I have some fairly long and complex queries and this is becoming a problem.
    Thanks for any help.
    I'm currently using Dreaweaver CS4 at home and CS5.5 at work.

    Thanks for your reply Kenneth, but that is not what I'm trying to accomplish. I'm looking for the HTML entities that exist in the source code which are & shy ; and & nbsp ; (without the spaces). As I mentioned above, if I enter them manually in the search box, I will get the corrrect results. If I save the search and then reload it, the special characters are no longer in HTML and the search is now useless.
    Just for example again
    In an open document in code view insert a number in the format (without the spaces): 888& nbsp;888& nbsp ;8888
    Open a search dialog box and enter (without the spaces): [\d]{3}& nbsp ;[\d]{3}& nbsp ;[\d]{4}
    The search will find that entry.
    Save search as phone.dwr for example. Then load it and try the search again. It won't work because upon loading the search Dreamweaver replaces the HTML code which was saved with the rendered HTML. So now the search shows up as: [\d]{3} [\d]{3} [\d]{4} which will not find the string with hard coded non-breaking spaces that I'm looking for.
    Basically I want to be able to save a search query for reuse. When I load a search query, I want it to be exactly what I saved, not something that DW has rendered (that doesn't work).

  • How do I search and replace for invisibles in Pages 5.5.2?

    Three related problems all involving search and replace for invisibles.
    1. A block of text where all double returns need to become single returns.
    2. A block of text where all returns need to be replaced with a single word space.
    3. A block of text where all double word spaces to be replaced with a single word space.
    Pages 09 could do all three this handily. How can these be done in Pages 5.5.2?
    Appreciated.

    Here are screenshot of my attempts to make reducing double returns to one. First up selection of a double return:
    Copy to the clipboard. Do a Command-F. Here's the resulting dialogue:
    I paste in the contents of the clipboard:
    Note the Search field no longer has an empty slot selected. Something is clearly in there, but no instance of whatever is has been found. Nevertheless, I proceed to set up the Replace field by selecting a single return:
    Copy that to the clipboard and paste into the Replace field:
    Nothing to search for and therefore nothing to replace. Am now wondering what that little scoop to the right of the eyeglass icon might indicate. Clicking on it reveals this:
    Definitely not "a solution that just works."

  • How do I search and replace in comments in Acrobat XI?

    I use a Mac and just downloaded Acrobat Pro XI specifically to search and replace phrases in comments in a large PDF. According to this Adobe Help page, I should be able to do this: https://helpx.adobe.com/acrobat/using/searching-pdfs.html I copied the relevant section below and marked with ***. However, I don't see I don't see an arrow for the options that would allow me to include comments. I understand how to include the comments with advanced search, but I want to also replace text. I also checked in preferences and searched the forums. Could someone please advise and maybe include a screenshot, if possible. Thanks!
    Choose Edit > Find (Ctrl/Command+F). 
    Type the text you want to search for in the text box on the Find toolbar. 
    To replace text, click Replace With to expand the toolbar, then type the replacement text in theReplace With text box. 
    (Optional) Click ***the arrow ***next to the text box and choose one or more of the following: 
    Whole Words Only 
    Finds only occurrences of the complete word you type in the text box. For example, if you search for the word stick, the words tick and sticky aren’t found.
    Case-Sensitive
    Finds only occurrences of the words that match the capitalization you type. For example, if you search for the word Web, the words web and WEB aren’t found.
    Include Bookmarks
    Also searches the text in the Bookmarks panel.
    ***Include Comments***
    Also searches the text of any comments.

    Here are screenshot of my attempts to make reducing double returns to one. First up selection of a double return:
    Copy to the clipboard. Do a Command-F. Here's the resulting dialogue:
    I paste in the contents of the clipboard:
    Note the Search field no longer has an empty slot selected. Something is clearly in there, but no instance of whatever is has been found. Nevertheless, I proceed to set up the Replace field by selecting a single return:
    Copy that to the clipboard and paste into the Replace field:
    Nothing to search for and therefore nothing to replace. Am now wondering what that little scoop to the right of the eyeglass icon might indicate. Clicking on it reveals this:
    Definitely not "a solution that just works."

  • Search and Replace in Pages 5

    Search and Replace in Pages is now seriously regressive. Previously I could search for "invisibles" in a document and globally replace the search "invisible" by a replace one. Now I can't find a way of doing that. Any suggestions?

    Try this:
    Turn on Show Invisibles in the View menu.
    Select (highlight) the double para breaks.
    Use Command-E  (Find using selected text).
    Open the Find dialogue box (Command-F) and select Find & Replace.The selected para breaks will be in the Find text entry box, but will not be visible!
    Click in the Replace text entry box.
    Select (highlight) a single para break.
    Go to the Edit menu / Find and select 'Use selection for replace' (it will not show in the Replace entry box).
    In the Find & Replace dialogue box, click on the Forward or Back arrows to highlight the selected items (e.g. double para break) where you wish to start replacing in the document.
    Use the Replace All / Replace & Find / Replace buttons as per usual.
    Not a nice solution, but I hope it gets you going until Apple restores the previous functionality!

  • Search and Replace in Dreamweaver

    Dreamweaver CS3has a nice search and replace tool allowing for search and replacement of very large text strings.
    Does anyone know of a good notepad editor that can handle that large of replace text strings.
    Seems like most cant handle that much code in terms of search and replace.
    thanks

    If you're looking for something free/cheap that handles multi-line search and replace in source code, then there's always TextWranger if you're on a Mac:
    http://www.barebones.com/products/TextWrangler/
    There are plenty of Windows equivalents, but none I've used extensively and could recommend. This one is free:
    http://www.htmlkit.com/
    ...and has a button to expand the find/replace fields for multi-line content.
    That being said, they're not really going to do anything DW can't if you're already using DW.

  • Bug in Multi-File Search and Replace in RH6?

    I'm using the 6.0 trial, and one thing I want to be able to
    do is to replace the variables I put in using JavaScript with the
    new feature variables in 6.0. So, I went in to multi-file search
    and replace, and searched for:
    <script
    language=JavaScript>document.write(varProduct)</script>
    I copied this code directly from a topic, and pasted it into
    the Search tool.
    I don't even care whether I can successfully copy the code
    from my new variable for use as the replacement text; I'd be happy
    if the multi-file search would simply find all occurrences of my
    original code so I don't miss any during conversion to 6.0.
    It keeps coming up as not found, and this concerns me
    greatly. Has anyone else experienced this? Is it a known bug? Does
    anyone have a workaround?
    Thanks!

    Hi robowriter
    I'm assuming you are using the wondrous little applet known
    as Multi-File Find and Replace.
    Unfortunately, this little beastie is like a cat. It
    frequently has a fussy tummy and loves to hork up furballs. Well,
    not exactly. Really what it does is fail to properly handle
    anything with a line break. So you need a tool that does do this.
    Fortunately, one exists! It is called FAR (Find And Replace). Oddly
    enough, it was also written by a fellow Microsoft Help MVP named
    Rob Chandler. (Rob lives in Australia)
    You can download a trial version of FAR from the FAR page.
    Click here to visit
    the FAR page
    Cheers... Rick

  • How can I search and replace fonts?

    iOS 7 doesn't support the Adobe workhorse fonts I've most relied on for years, and arbitrarily changes them to iOS built-in fonts when I link my standard documents and templates to the iPhone, via iCloud. There's no apparent logic to how it does this; a Pages document in Minion Pro, a serif font, gets changed to the sans-serif Helvetica. Myriad Pro may come out in Times New Roman. I accept that the iPhone's limited number of fonts makes translation necessary, but does Pages offer a way in which I can search and replace inappropriately substituted fonts for more logical alternatives?

    You noticed the first one yourself: the Found item list seems to randomly jump around the document -- I believe you are correct in your observation it may be due to the object construction order. That tells me, by the way, something about your lot numbers that tou didn't mention: your text is not one continuous long threaded story, but it's all or partially in disconnected etxt frames. The Found list does return everything inside a single story in the correct order, but it goes over each separate story in the order they were constructed.
    The only solution is to gather all of your lot numbers, *re-sort* them according to the page number they appear on (and some sort of Worst Case Scenario is when you might have more than one lot number frame per page; in that case you also need to sort by textframe, top to bottom -- yet even worse is if you also may have these textframes side by side!).
    Only then you have a reliable counting order.
    This isn't too bad. We can just extend the method I offered for sorting top-to-bottom/left-to-right in Re: Working around the frame selection order issue in CS 4 and make it also include page numbers:
    function byPageYX(a,b) {
        var
            aP = a.parentTextFrames[0].parentPage.index,
            bP = b.parentTextFrames[0].parentPage.index,
            aY = a.baseline[0],
            bY = b.baseline[0],
            aX = a.horizontalOffset[1],
            bX = b.horizontalOffset[1],
            dP = aP-bP,
            dy = aY-bY,
            dx = aX-bX;
        return dP?dP:(dy?dy:dx);
    myResults.sort(byPageYX);
    Or something like that.
    As for actually implementing the above I cannot be of any help with Applescript.
    Once we're dealing with sorting I think you're much better off in Javascript anyhow.

  • JS InDesign Server CS2 - Search and Replace

    I am struggling to get a search and replace script to work on InDesign Server CS2.
    This works on my Desktop CS2:
    app.documents[0].search('xxx', false, false, 'yyy');
    but not through InDesign Server CS2.
    Can any one please help.
    Thanks
    Simon Kemp

    Thanks for all of the replies.
    This situation is that the company I work for has decided to consolidate some of the duties of our graphics departments.  People in one location will be dummying documents for people at another location.
    The paths to the images are UNC paths, which means they're pointing to different shares on different servers.  This cannot be changed.
    Also, the images at either location may not exist until days after the dumming process.
    During the dummying process, the application that's used to build the pages places empty ad boxes (placeholders) on the page.  The placeholders are text frames.
    I don't understand in what way, but the paths to the images are hidden inside the InDesign file.  From the users' standpoint, the placeholders simply display basic information about the ad (customer name, ad number, etc.) and hold the position for the images that will be placed later.
    It is not using script labels to apply the paths.
    So, this is why I describe the problem as needing to do a search and replace inside the InDesign file.
    As I mentioned before, I know this is doable.  I think I now see that the problem problem is figuring out how these hidden paths are being applied in the document.  My only thought was script labels, but this is not the case...

  • Is there any "Search and Replace" option in Crystal Reports?

    Is there any option to search and replace in Crystal Reports. Since i am using a name in many of the formulas in crystal reports. I need to replace with the desired name on the go.
    Could anyone help me on this....

    Search & Replace across formulas is not available in CR XI but is available in CR 2008.  Here is an excerpt from the CR 2008 Users Guide:
    Searching for formula text
    You can use the Find dialog box to carry out a number of different activities:
    u2022 Search for text or characters in the Field, Function, or Operator trees.
    u2022 Search for text or characters that you want to mark or replace in the
    formula, Custom Function, or SQL Expression that you have open.
    u2022 Search for text or characters across all SQL Expressions in a report.
    u2022 Search for text or characters across all formulas and Custom Functions
    in a report.
    When you search for text across all formulas, the results appear in a pane
    at the bottom of the Formula Workshop. (You can dock the results pane in
    other locations). When you click an item in the results pane, Crystal Reports
    opens the appropriate formula and highlights the matching text.
    Tip: You can open the Formula Workshop to search across all formulas
    from the Field Explorer and from the body of a report. To do this, select a
    formula field, right-click it, and choose the "Find in Formulas" option.

Maybe you are looking for

  • PHP form help - results not appearing in email

    Hi I have set up a simple entry form, and I am submiting it using PHP to my email address, It works well when you fill the form in and send it, I receive the email however the email only displays the questions and not the answers that have been fille

  • InDesign Server to manage reporting services

    Hi, Im looking for help/guidelines regarding InDesign. I'm a software architect working on a line-of-business application that will eventually require printing about 5 hundred thousand personalized report (of about 20 pages each) over a couple of day

  • Audio Echo In P2P Apps

    I've been making a few p2p applications in flex that have to do with audio sharing between clients, and I've got a nasty issue with echo that I can't seem to subdue. We are able to minimize the effects by having every end user plug in their headphone

  • TimeOut Property in BPEL

    Hi, We have a requirement to Indroduce a Timeout Property to 60 secs at BPEL Process level. Usually TimeOut Property will be placed at Partner Link level. Is there any way to introduce the Timeout Property at BPEL Process level? We can change the BPE

  • BAPI_SAG_CHANGE: dump OBJECTS_OBJREF_NOT_ASSIGNED

    Hello, I have just written a custom report that calls BAPI_SAG_CHANGE. It works fine if run in foreground, but if run in background, with the same data, I get a dump: Runtime error OBJECTS_OBJREF_NOT_ASSIGNED Exception     CX_SY_REF_IS_INITIAL Some m