String Replace  has $

Hi All,
How do i replace the text with text that has $.
String s = "Sample text XYZ";
s.replaceAll(XYZ, "$ABC");
Error: Illegal Group Reference.
"\\$ABC" works.
In my case "$ABC" is dynamic text. Position of $ can be any where in in the text, need not be first char.
TIA,
Kishore.

I think you'd need to find the $ in your search string first and put the escape character in their before attempting to do the replace all. In case you're unaware, RegEx uses $ as a special character, so that's why it must be replaced..
String a = "This is XYZ";
String replace = "$ABC";
StringBuffer sb = new StringBuffer(replace);
sb.insert(sb.indexOf("$"), "\\ ");
a = a.replaceAll("XYZ", sb.toString());
System.out.println(a);(Note: The extra space after the \\ in the insert was just so this forum would display everything properly).

Similar Messages

  • Passing String Which Has Single Quote Row/Value to a Function Returns Double Quoate

    Hi, I'm getting weird thing in resultset. When I pass String which has single quote value in it to a split function , it returns rows with double quote. 
    For example  following string:
    'N gage, Wash 'n Curl,Murray's, Don't-B-Bald
    Returns:
    ''N gage, Wash ''n Curl,Murray''s, Don''t-B-Bald
    Here is the split function:
    CREATE Function [dbo].[fnSplit] (
    @List varchar(8000), 
    @Delimiter char(1)
    Returns @Temp1 Table (
    ItemId int Identity(1, 1) NOT NULL PRIMARY KEY , 
    Item varchar(8000) NULL 
    As 
    Begin 
    Declare @item varchar(4000), 
    @iPos int 
    Set @Delimiter = ISNULL(@Delimiter, ';' ) 
    Set @List = RTrim(LTrim(@List)) 
    -- check for final delimiter 
    If Right( @List, 1 ) <> @Delimiter -- append final delimiter 
    Select @List = @List + @Delimiter -- get position of first element 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    While @iPos > 0 
    Begin 
    -- get item 
    Select @item = LTrim( RTrim( Substring( @List, 1, @iPos -1 ) ) ) 
    If @@ERROR <> 0 Break -- remove item form list 
    Select @List = Substring( @List, @iPos + 1, Len(@List) - @iPos + 1 ) 
    If @@ERROR <> 0 Break -- insert item 
    Insert @Temp1 Values( @item ) If @@ERROR <> 0 Break 
    -- get position pf next item 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    If @@ERROR <> 0 Break 
    End 
    Return 
    End
    FYI: I'm getting @List value from a table and passing it as a string to split function.
    Any help would be appreciated!
    ZK

    fixed the issue by using Replace function like
    Replace(value,'''''','''')
    Big Thanks Patrick Hurst!!!!! :)
    Though I came to another issue which I posted here:
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/a26469cc-f7f7-4fb1-ac1b-b3e9769c6f3c/split-function-unable-to-parse-string-correctly?forum=transactsql
    ZK

  • String replace

    String has a replace method for chars, something the likes of
    String replace(char a, char b)
    I tend to think it would be nice to ammend String further with
    String replace(String a, String b)
    proponents/opponents? It seems like a nice thing to have.

    This type of method is available in the regex package
    (available in JDK 1.4). I am not expert or regular
    expressions but it will allow you to do this and much
    much more.I guess it will. Still it would be nice to have the ability directly inside String without explicitly having to instantiate a Pattern. I know there is a split method in String in JSDK 1.4 which takes a String specification of a regexp and internally compiles it. I guess my point is convenience but I should know the new APIs fully before writing more.

  • Dynamically Setting a Variable from a Connection String that has been set by a Config File

    Hi Guys
    I'm setting up a Master / Slave (Parent / Child) dtsx environment but I'm unable to work out how to dynamically set a variable in the Master dtsx from a connection string that has had its value set by a config file. I'm sure it's possible.
    Below is the what I'm hoping to achieve. I've set up everything apart from the highlighted section.
    Any ideas?

    First, what version of SQL Server are you using?
    You could switch the problem around.  You could set the value of a variable from the config file, then it is easy to use that variable as the connection string source for your connection manager.  At the same time you can use a parent variable
    configuration to map that variable to variables in your child package.
    Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

  • String replacement

    Hi, anyone knows how to replace a particular string in a file with another string?
    For example, in the file hello.tmp,
    I want to replace the word :Smile: with the string
    <img src="smile.gif">
    I tried to use String.replace() but this is only for characters.
    Anyone knows how to replace Strings??
    Hope to hear from anyone really soon. Very urgent!!!

    There is no direct method to replace a string in file. The code goes like this:
    import java.io.*;
    import java.util.*;
    public class StringReplacer
         private String replaceString;
         private String replacerString;
         private String filePath;
         public StringReplacer(String replaceString, String replacerString, String filePath)
              this.replaceString = replaceString;
              this.replacerString = replacerString;
              this.filePath = filePath;
              try
                   replace();               
              catch (Exception ex)
         private void replace() throws Exception
              File file = new File(filePath);
              if(!file.exists())
                   System.out.println("File doesnot exists");
                   return;
              DataInputStream dis = new DataInputStream(new FileInputStream(file));
              StringBuffer fileData = new StringBuffer("");
              String strTemp = "";
              while((strTemp = dis.readLine()) != null)
                   fileData.append(strTemp);
              dis.close();
              StringTokenizer stTemp = new StringTokenizer(fileData.toString(), replaceString);
              int tokens = stTemp.countTokens();
              if(tokens <= 1)
                   //No matches found for string to be replaces.
                   System.out.println("No matches found for string to be replaced");
                   return;
              fileData = new StringBuffer("");
              while(stTemp.hasMoreTokens())
                   fileData.append(stTemp.nextToken() + replacerString);     
              if(file.exists())
                   file.delete();
              file = new File(filePath);
              if(!file.exists())
                   file.createNewFile();
              DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
              dos.writeChars(fileData.toString());
              dos.flush();
              dos.close();
         public static void main(String [] args)
              //create an object of StringReplacer here.
    }

  • What is the unicode for ''  (need it to do String.replace)

    i'm trying to use String.replace(char a, char b)
    it won't compile if i do x.replace('_', '')
    help!
    thanks!

    Are you trying to remove all occurences of the underscore character from the string? If so create a StringBuffer from the string, loop through it and remove the characters as you find them.
    If you're using JDK1.4 you should eb able to use the new String method:
    public String replaceAll(String regex,
    String replacement)

  • Regarding String Replacing ....

    Hi Friends,
    I have some problem regarding String replacing.
    ex.
    I have following string ::
    =================================================
    This is the java manager the main purpose for the jasper is used to create reports.
    And the Java language is very extensible.
    Is this the proper string functions provided by java isn't it ?
    *================================================*
    *i want to replace word "is"  with "IS". but that word is not connected to word like  Th{color:#ff00ff}is{color}*
    *differ from simple separate "{color:#ff0000}is{color}" so Word should not be replaced in This only separate "is"*
    *must be replaced. ?*
    *Any Idea ?*
    *{color}*
    Edited by: Ghanshyam on Sep 14, 2007 4:27 PM

    How about just searching for and replacing
    " is "
    instead of
    "is"
    So, using this code from the Java Developers Almanac 1.4 (2002 Addison-Wesley):-
    static String replace(String str, String pattern, String replace) {>    int s = 0;>    int e = 0;>    StringBuffer result = new StringBuffer();> >    while ((e = str.indexOf(pattern, s)) >= 0) {>       result.append(str.substring(s, e));>       result.append(replace);>       s = e+pattern.length();>  result.append(str.substring(s));
    return result.toString();
    }Your would use:-
    String newStr = replace(originalStr, " is "," IS ");
    Edited by: mad_scientist on Sep 14, 2007 4:16 AM (Sorry about all the edits, just getting used to the formatting on here)
    Edited by: mad_scientist on Sep 14, 2007 4:22 AM
    Edited by: mad_scientist on Sep 14, 2007 4:24 AM

  • PLD String Replace Function?

    Hello Experts,
    I would like to use the Sum in Words option in the field properties Format tab. However, I would like to have this in a language for which there is no LRF.
    I have read all the various Sum in Words/Amount in Words threads I can find but I have no special locale based requirements (lacs etc). The default answer seems to be to prepare a FMS query and attach it to a UDF, then pull the variable into PLD.
    Rather than rewriting the functionality, it would be far easier for me to use a series of Replace functions (the structure of Turkish for amount in words is exactly the same as English and translating each word (One, Two... Ten, Twenty... etc) with a Replace would solve my problem.
    Looking at the documentation for PLD, I can see no prebuilt Replace function - is there any way this can be achieved?
    If not, is there any Sum in Words function in B1 queries so I can at least do the replace there rather than writing an entire convert to words query?
    Thank you.

    Wasn't able to force a string replace - had to hex edit the LRF instead. Quick and dirty, but it works.

  • Batch Rename with String Replacement?

    Is there a convenient way to batch rename files after they've been imported? The template mechanism seems to work well for creating new names, but not for renaming. For example, I originally imported and renamed my images to look like this:
    Zemke_YYMMDD_NNN-O1.CR2
    I decided I would rather have DRZ (My initials) instead of "Zemke" as the prefix. I was able to get it done with some contortions:
    Metadata/XMP/Export
    Remove all files from Lightroom
    Rename all the external files to start with DRZ
    Reimport all the files
    Delete the XMP files
    I think what is needed is for Rename to include string replacement (and string deletion) functionality. Is it already there?
    Dan

    Stefano, nonadjacent selection can be done by holding down Control and manually selecting the additional image. If you want to select a lot of separate ranges, the way to do it is to add each range to the quick collection (press the B key), then go to the quick collection and select all. It's exactly for those kinds of scenarios that quick collection exists. Once you get used to doing it, it's easier working with a "sticky" selection like the quick collection rather than the contortions required to extend standard selections.
    To slightly add to Rory's comments: two-digit year plus spelled out month names and day of the week names are also available. Combine into any order you want, with any additional supporting text anywhere you want it, and you've got huge flexibility there. And no matter how complex it is, you can save it as a preset so it's readily accessible later.

  • Whole word string replacement in LV7.1

    Is there anyway to do whole word string replacement in 7.1?
    For example, if I have the string "x21+sin(x2)" and I want to replace "x2" with "b2" without accidently changing "x21" into "b21". I saw that 7.1 does not support the word boundary "\b" in regex.

    The easy solution is to search for "(x2)" and replace with "(b2)" but if you're not sure that x2 will always be in parenthesis, then another solution would be to get the next character after "x2" is found, and if it is not a number (0-9) then you have found x2, if it is a number then you have found x21, or x22, etc.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • Help needed with String replace!

    Hi,
    I would like to replace all '\' characters with '/' in my string, ie:
         mystring.replace('\','/');
    Howeve, it complain about the '/' (Unclosed character literal).
    Any suggestions?
    Thanks

    Show us the line, you are probably using your regex incorrectly.
    In order to get the '\' you have to escape it (the '\' char. is used as the escape character so that you can look for things like " ' and new lines by useing \" \' and \n. Otherwise, how would java know you are looking for quotes and not closing your string?) As a consequence, your regex should look like '\\" for the \.
    The replace statement should probably be:
    string.replace("\\", "/");

  • PHP String Replace

    I am looking to add my date to the beginning of my articles.
    Previously, I
    was using the string replace function to look for the
    begininng of my
    paragraph and then place the date in front of that. Bad Jon!
    I forgot that
    any article with multiple paragraphs would then have multiple
    dates.
    $artContent = str_replace('<p>', '<p>
    '.$artDateEdited.' - ',
    $artContent);
    So, what I am looking for is how do I do a string replaceon
    just the first
    paragraph?
    TIA,
    Jon Parkhurst
    PriivaWeb
    http://priiva.net.

    Are you sure there are <p> tags in the data? The only
    way that could get
    there would be if someone explicitly put them there.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "crash" <[email protected]> wrote in message
    news:[email protected]...
    > LOL, just now getting back to this.
    >
    > I've got myself in a little bit of a bind, b/c I didn't
    foresee my data
    > having more than one paragraph.
    >
    > This is what I'm thinking of doing. If there's a better
    way, can somebody
    > pipe in?
    >
    > Take data from database.
    > Search for <p> tags, and capture all text within
    the first instances
    > Limit text to X number of chars
    > Replace <p> tags, and my ...Full Story links
    >
    > Looking now through all of the string functions and
    preg_replace right
    > now.
    >
    > Basically, I"m having some problems finding a function
    that will replace
    > $var on the Xth instance.
    >
    > Will post tomorrow with my results.
    > "Joe Makowiec" <[email protected]> wrote in
    message
    >
    news:[email protected]...
    >> On 26 Aug 2006 in macromedia.dreamweaver.appdev,
    crash wrote:
    >>
    >>> I am looking to add my date to the beginning of
    my articles.
    >>> Previously, I was using the string replace
    function to look for the
    >>> begininng of my paragraph and then place the
    date in front of that.
    >>> Bad Jon! I forgot that any article with multiple
    paragraphs would
    >>> then have multiple dates.
    >>>
    >>> $artContent = str_replace('<p>',
    '<p>
    >>> '.$artDateEdited.' - ',
    >>> $artContent);
    >>>
    >>> So, what I am looking for is how do I do a
    string replaceon just the
    >>> first paragraph?
    >>
    >>
    http://www.php.net/manual/en/function.preg-replace.php
    >>
    >> In particular, the optional 4th parameter to
    preg_replace() is a limit;
    >> you can set this to 1.
    >>
    >> --
    >> Joe Makowiec
    >>
    http://makowiec.net/
    >> Email:
    http://makowiec.net/email.php
    >
    >

  • Very simple XSLT string replacing question

    Hi,
    This is a really simple question for you guys, but it took me long, and i still couldn't solve it.
    I just want to remove all spaces from a node inside an XML file.
    XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <root insertedtime="2008-05-01T14:03:00.000+10:00" pkid="23421">
       <books>
          <book type='fiction'>
             <author>John Smith</author>
             <title>Book title</title>
             <year>2 0  0 8</year>
          </book>
       </books>
    </root>in the 'year' node, the value should not contain any spaces, that's the reason why i need to remove spaces using XSLT. Apart from removing space, i also need to make sure that the 'year' node has a non-empty value. Here's the XSLT:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:strip-space elements="*"/>
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="//books/book[@type='fiction']">
            <xsl:copy>
                <xsl:apply-templates select="@*"/>
                <xsl:attribute name="id">101</xsl:attribute>
                <xsl:call-template name="emptyCheck">
                    <xsl:with-param name="val" select="year"/>
                    <xsl:with-param name="type" select="@type"/>
                    <xsl:with-param name="copy" select="'true'"/>
                </xsl:call-template>
                <xsl:value-of select="translate(year, ' ', '')"/>
            </xsl:copy>
        </xsl:template>
        <!-- emptyCheck checks if a string is an empty string -->
        <xsl:template name="emptyCheck">
            <xsl:param name="val"/>
            <xsl:param name="type"/>
            <xsl:param name="copy"/>
            <xsl:if test="boolean($copy)">
                <xsl:apply-templates select="node()"/>
            </xsl:if>
            <xsl:if test="string-length($val) = 0 ">
                <exception description="Type {$type} value cannot be empty"/>
            </xsl:if>
        </xsl:template>
    </xsl:stylesheet>The 'emptyCheck' function works fine, but the space replacing is not working, this is the result after the transform:
    <?xml version="1.0" encoding="utf-8"?>
    <root insertedtime="2008-05-01T14:03:00.000+10:00" pkid="23421">
       <books>
          <book type="fiction" id="101">
             <author>John Smith</author>
             <title>Book title</title>
             <year>2 0 0 8</year>2008</book>
       </books>
    </root>The spaced year value is still there, the no-space year is added outside the 'year' tags'
    anyone can help me, your help is extremely appreciated!
    Thanks!

    You should add a template for 'year' :<xsl:template match="year">
    <year><xsl:value-of select="translate(.,' ','')"/></year>
    </xsl:template>and remove the translate call in the 'book' template.
    It would be better to add a 'priority' attribute at each template so it would be explicit which template to use because match="@*|node()" could be interpreted by another transform engine as the unique template to be used !

  • Partial string replacement

    Let's say I have an XML variable like the following:
    <AWARDS d-type="String">Booklist 2002 - Twenty Best
    Bets for Student Researchers | IHOP Best Reads While Consuming Far
    Too Much Coffee 2002</AWARDS>
    and I want to replace the | with <br> when the variable
    is kicked out in a spry loop.
    Is there an easy way to do that?

    Hi Killane,
    Try this:
    // Add a function that will pre process the data after it has
    loaded.
    ds.addObserver(MyPreProcessDataFunc);
    function MyPreProcessDataFunc(notificationType, notifier,
    data)
    if (notificationType != "onPostLoad")
    return;
    var rows = ds.getData();
    for (var i = 0; i < rows.length; i++)
    rows[ i ].AWARDS = rows[ i ].AWARDS.replace(/\|/, "<br
    />");
    --== Kin ==--

  • Identifying patterns in a string & replacing all characters with 1st digit

    Morning folks. Interesting problem on hand. I have a situation where I have a varchar2 text field where I have different paterns of a sequence of numbers somewhere in the string. I guess, I could write a function where by I accept the whole string and then identify one of the patters below and then finally replace only the recognized pattern with the first digit all the way through to the end of that pattern.
    The catch here is that there could be free text before and after the string but there will be spaces when free text ends and the patern begins.
    Here are a few patterns I would be interested in. The MAX length is 19 as in Cases 1 and 3.
    1. 9999 9999 9999 9999
    2. 9999999999999999
    3. 9999-9999-9999-9999
    4. 9999-9999-99-99999
    5. 9999-999999-99999So, here would be an example of the problem in hand :
    Call received on 9/22/2009.
    5123-4532-8871-9876
    Please follow up by 10/22/2009So, the desired output would be :
    Call received on 9/22/2009.
    5555-5555-5555-5555
    Please follow up by 10/22/2009Any ideas ? I am stumped at the fact of before and after text in the string, hence the question for you guys !
    Thanks !

    Here is another solution. However there has to be a better way! (I'm not a regular expression expert).
    SQL> WITH test_data AS
      2  (
      3          SELECT 'Call received on 9/22/2009.
      4          1232 3456 8765 3456
      5          Please follow up by 10/22/2009' AS DATA FROM DUAL UNION ALL
      6          SELECT 'Call received on 9/22/2009.
      7          1232345687653456
      8          Please follow up by 10/22/2009' AS DATA FROM DUAL UNION ALL
      9          SELECT 'Call received on 9/22/2009.
    10          1232-3456-8765-3456
    11          Please follow up by 10/22/2009' AS DATA FROM DUAL UNION ALL
    12          SELECT 'Call received on 9/22/2009.
    13          1232-3456-86-3456
    14          Please follow up by 10/22/2009' AS DATA FROM DUAL UNION ALL
    15          SELECT 'Call received on 9/22/2009.
    16          1232-345687-3456
    17          Please follow up by 10/22/2009' AS DATA FROM DUAL
    18  ), substring AS
    19  (
    20          SELECT  DATA AS SOURCE
    21          ,       REGEXP_INSTR
    22                  (
    23                          DATA
    24                  ,       '(([[:digit:]])+[[:space:]|-]){1,}'
    25                  ) AS PATSTART
    26          ,       REGEXP_SUBSTR
    27                  (
    28                          DATA
    29                  ,       '(([[:digit:]])+[[:space:]|-]){1,}'
    30                  ) AS PATTERN
    31          ,       19 AS MAXLENGTH
    32          FROM    test_data
    33  )
    34  SELECT  SUBSTR
    35          (
    36                  SOURCE
    37          ,       1
    38          ,       PATSTART-1
    39          ) ||
    40          TRANSLATE
    41          (
    42                  PATTERN
    43          ,       '0123456789'
    44          ,       LPAD
    45                  (
    46                          SUBSTR
    47                          (
    48                                  PATTERN
    49                          ,       1
    50                          ,       1
    51                          )
    52                  ,       10
    53                  ,       SUBSTR
    54                          (
    55                                  PATTERN
    56                          ,       1
    57                          ,       1
    58                          )
    59                  )
    60          ) ||
    61          SUBSTR
    62          (
    63                  SOURCE
    64          ,       PATSTART + MAXLENGTH
    65          )       AS NEW_STRING
    66  FROM substring
    67  /
    NEW_STRING
    Call received on 9/22/2009.
            1111 1111 1111 1111
            Please follow up by 10/22/2009
    Call received on 9/22/2009.
            1111111111111111
          Please follow up by 10/22/2009
    Call received on 9/22/2009.
            1111-1111-1111-1111
            Please follow up by 10/22/2009
    Call received on 9/22/2009.
            1111-1111-11-1111
           Please follow up by 10/22/2009
    Call received on 9/22/2009.
            1111-111111-1111
          Please follow up by 10/22/2009
    SQL>

Maybe you are looking for

  • Displaying values in a new page

    I have a java script code. At the end when the user clicks on the button after entering the values in the 3rd page, the values shall be displayed in a new page. Please help me out with the final approach: <html> <head> <script language="LiveScript">

  • Import Mail and Contacts, from Windows XP-based Thunderbird Email to New iPad Air

    Just got a New iPad Air, and I want to import all of my email & contacts (email addresses) from a Windows XP-based Thunderbird Email program. Does anyone know how to do this? Thank you in advance!

  • How to pass a String as a NUMC in backwnd table

    Hi All I have a Backend Table with the Field name : PERNR, having Type as "NUMC" From portal I have got the Selcted Pernr in a form of a String. But when I am passing this to table, it gives me below error at runtime  : com.sap.aii.proxy.framework.co

  • OMS not starting up

    Hi, i have installed oemgc in linux platform.while starting up gc from startup the oracle management server is showing status as failed.It was working fine till there was a reboot.All the other services are working.I have the db in the same server wh

  • Getting slower speeds if using Apple Time Capsule?...

    Hi. Have had Infinity2 for a couple of weeks and am happy with the sevice - much faster than my old Virgin cable. When the engineer came he installed the white modem box and connected it to a Home Hub 4. With Virgin I used the Superhub in "modem" mod