Replacing all " into \" in a string.

I have a huge string which contains ". I have to change all the " into \". I tried the String.replace( ) but not sure how to make it work. I need that special escape character to specify for the replacement. Please help.....

Try replaceAll( string, string).Not quite so simple as implied by this. The first parameter is a regular expression and the second is related to a regular expression. What you need is
            String aNotSoHugeString = "jlk\"fal auf\"ha fi\nhfaj\"hflkj ljkfh jfa\"ljf\n";
            String updatedNotSoHugeString = aNotSoHugeString.replaceAll("\"","\\\\\"");To understand more check out java.util.regex.Pattern.
:-( One day I might catch up with the rest of the world!
Message was edited by:
sabre150

Similar Messages

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

  • Replace all the " in a string.

    Hi all,

    I bow my head before you, oh Arrogant Other One.
    You are a great opponent to The Arrogant One (wasn't it jverd?)

  • Replace all special characters in a String with underscore

    I have a String which contains some special characters even(!,$,@,*....).
    I need to replace all the special characters with _ in my String. I do have an idea of using String.replace() and analogous forms, but I would be thankful if anyone can suggest me of a better and an efficient way.
    regards,
    fun_one

    Kaj,
    Thx for your earnest reply. I did have a peep into the API on this method. But the regular expression that I need to use here was beyond my understanding. It did specify some regex that I put to use (something like myString("\D","_"), assuming that I need to replace all non-digit characters ), but it really did not help me getting the result.
    Would you spare some code for me reg. the usage of regular expressions in such a scenario?
    cheers,
    fun_one

  • Replace all ', , ' inside string

    i have long string and with pl/sql i want to replace all ', ,' with ', null,'.
    I can use replace function like:
    prepare_insert := replace(prepare_insert,', ,',', null,');
    but it will only replace first ', ,' not all. How can i replace all?

    5th database commandment:
    Thou shalt not create dynamic insert statements!
    I think using bind variables or the using clause in the execute immediate statement would solve the problem.
    But of cause you can do it also the hard (and slow) way.
    The problem is that your search string is not correct. It does include a leading "," and leaving ",". However if the leavaing "," is also the leading "," of the next replacement part then the function can't take this into account.
    Solution 1) Take care of this while building the string in the first place.
    While concating the pieces togeather use NVL(value,'null'). If you are sure that there s no value, then write NULL.
    Solution 2) Use a double replace
    with testdata as (select 'Test, , , , ''ABC''' txt from dual union all
                      select 'Test2, , , ''ABC''' txt from dual
    select txt
          ,replace(replace(txt,', ,',',null,'),', ,',',null,')
    from testdata;
    TXT               REPLACE
    Test, , , , 'ABC'     Test,null,null,null, 'ABC'
    Test2, , , 'ABC'     Test2,null,null, 'ABC'

  • Replacing all occurrences of characters in a string with one new character?

    Hi there,
    I'm looking for a way that I could replace all occurrences of a set of specific characters with just one new character for each occurrence.
    For example if I have a string which is "word1...word2.......word3....word4............word5" how would I be able to replace this with just one character such as ":" for each set of "." so that it would essentially appear like this "word1:word2:word3:word4:word5"
    If I just use replace(".", ":") I am left with "word1:::word2:::::::word4::::word5::::::::::::"
    So therefore I'm guessing this would require the use of replaceAll() maybe? but I'm not really very familiar with how regular expressions work and how this would be accomplished using them.
    Any help would be greatly appreciated :) Thanks.

    Yes, but "." means any character, so ".\+" means "any character repeated more than once". If you just mean a full stop ("period" for you Americans :p) you should use "\.+" as your regular expression, but remember that for Java you need a '\' escape to recognise '\' as '\', so in code you'd actually type your regex as:
    "\\.+"Here's an example of one way to do it:
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Test {
        public static void main(String[] args) {
           String string = "example1.......example2...example3.....example4";
         Pattern pattern = Pattern.compile("\\.+");
         Matcher stringMatcher = pattern.matcher(string);
         string = stringMatcher.replaceAll(":");
         System.out.println(string);
    }Edited by: JohnGraham on Oct 24, 2008 5:19 AM
    Edited by: JohnGraham on Oct 24, 2008 5:22 AM

  • Replace all occurrences of ENTER in a string

    Hi,
    I have a string which contains line breaks:
    '<HTML><HEAD>
    </HEAD>
    <BODY>'
    and it is shown to me in the debugger as:
    '<HTML><HEAD>#</HEAD>#<BODY>'
    Now I want to replace all line breaks in the string,
    but
    replace all occurrences of `#` in text with ' '.
    doesn't work.
    So if you have an idea how to replace the # symbol for Enter in a string please tell me ;).
    regards,
    Stefan

    Hi,
    Pls use
    replace all occurences of '#' in text with cl_abap_char_utilities=>newline.
    Eddy

  • Replace all in a string

    Hello,
    I need to replace all occurences of
    <image>url to a image goes here</image>
    to
    <img src="url to a image goes here"/>
    where "url to a image goes here" is a url to an image
    Could you let me know how the call to replaceAll method will look like?
    Thank you.

           line = line.replaceAll("<image>([^<]*)</image>", "<img src=\"$1\"/>");

  • I downloaded all into a new external hard drive because my internal hard drive was failing. then got internal hard drive replaced by Apple Store. Now when I try to sync IPAD or IPhone to IMAC, photos will not transfer. Why? What shall I do?

    Trying to download photos from IPHONE, IPAD to IPHOTO in IMAC after installing new hard drive. Before getting new Hard drive, I downloaded all into external hard drive. photos did not download!

    Trying to download photos from IPHONE, IPAD to IPHOTO in IMAC after installing new hard drive.
    How did you import the photos to iPad and iPhone?
    If the photos have been synced to the iPhone and iPad using iTunes, you cannot sync them back.
    See this document:  http://support.apple.com/kb/HT4236
    You can't reimport pictures synced from your computer to your device back to your computer. You can only import pictures in the Camera Roll or Saved Photos from your device to your computer. If you need to retrieve synced photos from your device:
    If your photos are not in the Camera Roll on your devices, save them to the Camera Roll, share them to the Photo Stream, mail the photos, or, if you have iPhoto on the devices, use iTunes Photo Sharing.
    http://help.apple.com/iphoto/iphone/2.0/?handbuch#blnkee26bc1
    Save photos to your computer using iTunes
    Connect your iOS device to your computer.
    Tap a photo, album, event, web journal, or slideshow and tap Share> iTunes.
    Tap Selected, or change the photos you want to save (if you are saving a slideshow skip to step 4):
    Select different photos: Tap Choose Photos, tap one or more photos, and tap Next.
    Select a range of photos: Tap Choose Photos, tap Range, tap the first and last photos in the range, and tap Next.
    Select all the photos in an album or event: Tap All.
    In iTunes, click the button for your device and click Apps at the top of the window.
    Below File Sharing, select iPhoto (in Apps).
    Select the Shared Photos folder under iPhoto Documents.
    Click Save To and select the location on your computer where you want to save the items.
    To view your photos, go to the Finder and look in the location you selected above.

  • Replacing a character in a String

    Hi All,
    How can I replace a character ' which appears in a String into \'

    There is a method in String that replaces all
    occurrences of one character with anothercharacter.
    It's called, hold your breath now, "replace".But tho OP wants to replace one character with two
    characters :)You're right, I missed that. Well, serves me right for being sarcastic. :-)

  • DUMP: replace all occurrences of space in string1 with string2.

    Why does this statement results in a dump:
    replace all occurrences of space in string1 with string2.
    same with
    replace all occurrences of ' ' in string1 with string2.
    string2 is a string without spaces!
    Is there any drawback on using this statements as a workaround?
    while sy-subrc eq 0.
      replace space with string2 into string1.
    endwhile.
    Thanks
    norbert

    Hi,
    See this example i got from ABAPDOCU
    replacing values
    DATA: t4(10) TYPE c VALUE 'abcdefghij',
          string4 LIKE t4,
          str41(4) TYPE c VALUE 'cdef',
          str42(4) TYPE c VALUE 'klmn',
          str43(2) TYPE c VALUE 'kl',
          str44(6) TYPE c VALUE 'klmnop',
          len4 TYPE i VALUE 2.
    string4 = t4.
    WRITE string4.
    REPLACE str41 WITH str42 INTO string4.
    WRITE / string4.
    string4 = t4.
    REPLACE str41 WITH str42 INTO string4 LENGTH len4.
    WRITE / string4.
    string4 = t4.
    REPLACE str41 WITH str43 INTO string4.
    WRITE / string4.
    string4 = t4.
    REPLACE str41 WITH str44 INTO string4.
    WRITE / string4.
    SKIP.
    ULINE.
    Example for condensing strings
    DATA: string9(25) TYPE c VALUE ' one  two   three    four',
          len9 TYPE i.
    len9 = strlen( string9 ).
    WRITE: string9, '!'.
    WRITE: / 'Length: ', len9.
    CONDENSE string9.
    len9 = strlen( string9 ).
    WRITE: string9, '!'.
    WRITE: / 'Length: ', len9.
    CONDENSE string9 NO-GAPS.
    len9 = strlen( string9 ).
    WRITE: string9, '!'.
    WRITE: / 'Length: ', len9.
    SKIP.
    ULINE.
    Thanks & Regards,
    Judith.

  • Replacing all text in book with sample text

    Hello fellows,
    Is there a way to replace all the textual content in a book with some sample text using Extendscript?
    If yes, could you please point me to the relevant APIs?
    Thank you for your help in advance!

    Yes, the point that Rick was making crossed my mind, too. Using regular expressions, you can easily specify which characters should be replaced. Listing a number of same-width characters and replacing them with an "x" is as easy as this:
    sTextString.replace ( /[abcdefghknopqrsuvyz]/g, "x" );
    This would leave the non-mentioned characters as they are. Depending a little bit on the fonts that are used, of course, as they might have different character widths for more than the ones I left out. But even if you only replace a couple of characters throughout the doc, it would be enough to get the desired effect.
    The difficulty is getting to the text strings and also to replace them. There are many objects for which a GetText method exists, but you have to set the flags such that you actually get the right text strings out of that method. And then you have to figure out where in the doc the text string is, then delete the existing one and add the replacement. All of this has to be done without deleting any markers or anchors.
    Another approach might be to set the text location to the first character in the main flow and then walking through the entire document character by character, testing each one and replacing it where required. But I don't think you would get into tables with that method, as those are linked to the running text via an anchor in that running text. So the table cells will have to be processed separately. And if you do have a method to change text in table cells, you can use that method on all paragraphs.
    I think Rick has more experience in tweaking text strings. I am usually working on structured documents and only handling the element objects and their hierarchy, not so much changing the text content of documents. Rick, do you have an approach to walk through all text strings in a document and replace them without breaking anything ?
    Ciao
    Jang

  • Replace complete words by another string

    Hi,
    I'm searching for a possibility to replace complete words inside a string.
    For example I want to replace "quick" by "slow":
    "The <b>quick</b> brown fox is running quicker then the slow brown fox".
    The result shall be:
    "The <b>slow</b> brown fox is running quicker then the slow brown fox".
    The problem is, that the built in "Replace"-Method would also replace "quicker" by "browner".
    Furthermore, words beetween different signs (e.g. , . ; : - ! " ? ') shall also be found as complete word.
    I already searched for a FM but didn't find anything. Regular expressesions are also not possible because we are running on 6.40.
    Maybe anybody can help me with a simple FM or something else.
    Best regards,
    Stefan

    Hi Stefan,
    There is a crude way of doing this....with lots of loops..
    You can use the SPLIT statement
    SPLIT dobj AT sep INTO
          { {result1 result2 ...} | {TABLE result_tab} }
          [IN {CHARACTER|BYTE} MODE].
    and break the sentence into words using space as delimiter. Once you have all the words in a internal table, you can loop through it and compare each word with the word you want.
    This will solve the problem, but will not be performant enough.
    Regards,
    Vinodh

  • Return all instances of a string value

    I know that similar questions have been asked before but I am having a tough time getting things to work.
    I would like to search for all instances of a string value (shown red) and return the corresponding values in the adjacent cells (shown green) so that each room number is represented.  For example, I want the search for "Adequately" to return rooms 236 and 237 (and 237 just once even though it is listed twice).  Is this possible?
    Any help is appreciated.
    Clay

    Here's an example, similar in some ways to Yvan's, but taken a bit further.
    Data table (left) contains only the original data. I've shortened the ratings to allow an easier fit on this page.
    Summary table does the work in two stages.
    Pulls the room numbers for rooms matching each rating. (yellow portion of table. If desired, these rows may be hidden.
    Builds a list of these for each condition. (Footer row)
    Formulas (all on Summary)
    Row 1 is a header row, and contains the Rating labels, which must match those used on the Data table.
    B2:   =IF(AND(Data :: $E2=B$1,COUNTIFS(Data :: $E$2:$E2,B$1,Data :: $C$2:$C2,Data :: $C2,Data::$B$2:$B2,Data :: $B2)=1)," "&Data :: $B2&" "&Data :: $C2&" ","")
    Fill right to column F. Fill down to row 16 (as many rows as there are data rows on Data)
    Note the " " at the beginning and end of the 'if true' part: " "&Data :: $B2&" "&Data :: $C2&" "
    There is a single space between each pair of quotation marks. These are necessary to the second formula below.
    Row 17 is a Footer row.
    B17:  
    =IF(COUNTA(B)-COUNTBLANK(B)=0,"",TRIM(SUBSTITUTE(CONCATENATE(B2,B3,B4,B5,B6,B7,B 8,B9,B10,B11,B12,B13,B14,B15,B16),"  ",",
    There is a return character in the formula immediately before the last quotation mark. Press option-return to enter a return into a formula.
    SUBSTITUTE finds the two spaces added between items in the list and replaces them with a comma followed by the return noted above.
    TRIM is used to remove the single space before the first item in the list and the single space after the last.
    Regards,
    Barry

  • How to convert  information of a job posting into a xml string or file

    hi hr experts,
    I hope to find some answers.
    Is there a function in the ERP system that converts all the information of a job posting into a xml string or file?
    This could be used to communicate with external job databases, e.g. monster or jobpilot.
    The function CALL TRANSFORMATION converts data to XML. Is this really the only way to convert the job posting?
    Thanks for your feedback and help.
    Ralf von Seht
    Edited by: Ralf von Seht on Mar 26, 2008 4:45 PM
    Edited by: Ralf von Seht on Mar 26, 2008 4:46 PM

    Hi Elena,
    The issue is caused by XSLT is not script enabled by default.  Please provide XsltSettings in the loading to fix the issue. For more information, please see:
    http://daomingworks.wordpress.com/2009/12/11/xslt-transform-data-error-use-the-xsltsettings-enablescript-property-to-enable-it/
    Thanks,
    Jinchun Chen
    Jinchun Chen
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff AT microsoft.com(Please replace AT with @)

Maybe you are looking for

  • Ajax cascading lov not work

    Dear Pakar i follow instruction in http://apexlib.svn.sourceforge.net/viewvc/*checkout*/apexlib/trunc/Documentation/HowToInstall.html i'm using Application Express 3.0 & 10g express edition in debug form show 0.16: Computation point: BEFORE_FOOTER 0.

  • How do I get a url link for my form on FormsCentral so I can post on my website?

    I have uploaded my own PDF form to FormsCentral and want to post its URL on my website so anyone can fill it out. I was able to do this with Acrobat using its 'forms' function last year but can't find this functionality on FormsCentral. Any help?

  • How to make helvetica the default font for Endesign?

    everytime that I create a document, times is the default font, but most of the time I use helvetica and I want to make it the default font. thanks.

  • EPS/in directory

    Hi everyone! Does anyone know if it is safe to delete all the files in the EPS/in directory after a support package has been applied? Might it be any impact by doing that? Thanks in advance. Paulo

  • Transportation chain / multimode transport

    Dear All, 1) I got lots of documents for Transportation chain / multimode transport but not able to configure it. Could you please share me the steps involves and brief about configuring Multimode transport such as how many shipment document types /