Replace characters in StringBuffer

I am importing some XML data using Java code and importing the data into an Oracle database, but there is at least one wierd character in the data. The character looks like an apostrophe (what most people call a single-quote), but it's not the apostrophe which is under the quotes (aka double-quote) on the keyboard, and it is not the apostrophe under the tilde (aka squiggly) on the upper left of the keyboard. As far as I can tell, it is stored as hex character 92. When the data displays, the character displays wrong (it displays as an unfilled box).
I need to change my import routine to convert this character, whenever it occurs, to an apostrophe (aka single-quote). Anyone know how to do that?
Thanks.
-Jeff
Message was edited by:
JavaJeffrey

I am importing some XML data using Java code and
importing the data into an Oracle database, but there
is at least one wierd character in the data. The
character looks like an apostrophe (what most people
call a single-quote), but it's not the apostrophe
which is under the quotes (aka double-quote) on the
keyboard, and it is not the apostrophe under the
tilde (aka squiggly) on the upper left of the
keyboard. As far as I can tell, it is stored as hex
character 92. When the data displays, the character
displays wrong (it displays as an unfilled box).Displays where? This just sounds like a codepage issue to me.
I need to change my import routine to convert this
character, whenever it occurs, to an apostrophe (aka
single-quote). Anyone know how to do that?String.replaceAll?

Similar Messages

  • Problem in replacing characters of a string ?

    Hello everybody,
    I want to replace a few characters with their corresponding unicode codepoint values.
    I have a userdefined method that gets the unicode codepoint value for a character.
    1. I want to know how to replace the characters and have the replaced string after the comparision is over in the for loop in my main.
    Currently , i am able to replace , but i am not able to have the replacements done in a single variable.
    The output of the code is
    e\u3006ame
    ena\u3005e
    But i want the output i require is,
    e\u3006a\u3005e
    Please offer some help in this regard
    import java.io.*;
    class Read1
         public static void main(String s[])
             String rp,snd;
             String tmp="ename";
             for(int i=0;i<tmp.length();i++)
                 snd=getCodepoint(tmp.charAt(i));
                 if(snd!=null)
                    rp=replace(tmp,String.valueOf(tmp.charAt(i)),"\\u"+snd);
                    System.out.println(rp);
    public static String replace(String source, String pattern, String replace)
         if (source!=null)
             final int len = pattern.length();
             StringBuffer sb = new StringBuffer();
             int found = -1;
             int start = 0;
             while( (found = source.indexOf(pattern, start) ) != -1)
                 sb.append(source.substring(start, found));
                 sb.append(replace);
                 start = found + len;
             sb.append(source.substring(start));
             return sb.toString();
         else return "";
    ...,Any help in this regard would be useful
    Thanks
    khurram

    This manual replacement thingy reminds me of quite an old technique, when
    64KB of memory was considered enough for 20 users (at the same time that is!)
    Suppose you have a buffer of, say, n characters. Starting at location i, a region
    of chars have to be swapped with bytes starting at location j >= i+l_i; the lengths
    of the two regions are l_i and l_j respectively.
    Suppose the following method is available:public void reverse(char[] buffer, int f, int l_f) {
       for (int t= f+l_f; --t > f; f++) {
          char tmp=buffer[f]; buffer[f]= buffer[t]; buffer[t]= tmp;
    }i.e. the above method reverses a region of characters, starting at position f
    with length l_f. Given this simple method, the original problem can be solved
    using the following simple sequence:reverse(buffer, i, j+l_j);
    reverse(buffer, i, l_j);
    reverse(buffer, i+l_j, j-i-l_i);
    reverse(buffer, j+l_j-l_i, l_i);Of course, when replacing characters we don't need the last reversal.
    kind regards,
    Jos (dinosaurus)

  • Address book: Find and replace characters?

    Hi all,
    I just imported VCF file from Outlook to Address book. I am in Iceland and the Icelandic characters came wrong. Is there any way to batch find and replace characters in Address book? That is in individual cards.
    Thanks,
    Hilmar

    I believe the only way would be to write an AppleScript.

  • Replacing characters in a specific region of a String?

    I would like to change characters in a specific region of String.
    For example... change String from "leone24" to "leone31".
    I am not looking to change the occurance of 24 to 31 but the region of 5 to 6, in the above String, from 24 to 31. The characters in this region of the String will vary but the region will always be the position of characters that I want to change in the String.
    Thanks in advance,
    D

    This can be easily done with a StringBuffer:StringBuffer sb = new StringBuffer("leone24");
    sb.replace(5,7,"31");
    String newString = sb.toString();

  • Problem replacing characters

    Hi,
    I'm trying to replace a # with a � in a unix environment using a String.replace, but unix won't recognise the �. It just prints out a ? if I print to screen or a \243 if I print to a file. If I move this file back to windows, it contains ��. I'm very confused. Please help.
    Thanks.
    Oh, here's a copy of the test code of where I'm upto at the moment after alot of messing about. Feel free to disregard this code if I'm barking completely up the wrong tree.
        public static void main(String[] args) throws Exception {
            StringBuffer stb = new StringBuffer("#1234");
            int indx = -1;
            while ((indx = stb.toString().indexOf("#")) != -1) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                baos = new ByteArrayOutputStream();
                baos.write((new String("�").getBytes("UTF-8")));
                String st = baos.toString("UTF-8");
                System.out.println("st = " + st);
                stb.replace(indx, indx+"#".length(), st);
            System.out.println("buffer: " + stb.toString());
            //this is just here to see what happens if I write
            //the � to a file
            FileOutputStream fos = new FileOutputStream("file.txt");
            fos.write((new String("�").getBytes("UTF-8")));
            fos.flush();
            fos.close();
        }

    For character replacement, it's more efficient to use:
    str = str.replace('#', '�'); // where str is a string
    You don't need UTF-8 encoding if the Unicode characters are in the ANSI range: U+0000 - U+00FF. Just use the default encoding. When you view the file, make sure select a font that has the glyph for that charater. On Windows, Tahoma, Courier New, or Times New Roman would suffice.
    For those beyond ANSI, then UTF-8 comes into play. Use OutputStreamWriter(fos, "UTF8") when write to file. Check http://java.sun.com/docs/books/tutorial/i18n/text/stream.html for usage. Win9x/Me Notepad can't read UTF-8 encoded files, but WinNT/2K/XP can.

  • VBA Word Find and Replace characters but excluding certain characters

    I am trying to write VBA code in Word that I will eventually run from a VBA Excel module. The aim of the project is to find specific strings in the open Word document that have length of either one or two characters and are of a certain format, and replace
    them with other strings in the same format. This is to do with transposing (i.e. changing the musical key) of chord symbols in a songsheet in Word. The Find and Replace strings are contained in ranges in an Excel workbook, which is why I want to eventually
    run the code from Excel. I'm much more experienced in writing VBA code in Excel than in Word, and I'm fairly confident with transferring the 'Word VBA' code into an Excel module.
    At the moment I'm trying out code entirely in Word, and I've come across a stumbling block. For example, I want it to Find "A" and replace with "B",
    BUT only if the "A" is NOT followed by "#" (sharp) or "b" (flat).
    Here is the code I've got in Word VBA, which I obtained by editing code produced by the recorder:
    Sub F_R()
    'Find text must have specific font
    With Selection.Find.Font
    .Bold = True
    .Underline = wdUnderlineWords
    .Superscript = False
    .Subscript = False
    End With
    'Replacement text must have specific font
    With Selection.Find.Replacement.Font
    .Bold = True
    .Underline = wdUnderlineWords
    .Superscript = False
    .Subscript = False
    End With
    'Find & Replace strings
    With Selection.Find
    .Text = "A" 'hard-coded here for testing, but this will
    'eventually be referenced to a cell in Excel
    .Replacement.Text = "B" 'hard-coded here for testing, but this will
    'eventually be referenced to a cell in Excel
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = True
    .MatchWholeWord = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    For the Find & Replace section I want to do something like:
    With Selection.Find
    .Text = "A"
    .Text <> "A#"
    .Text <> "Ab"
    .Replacement.Text = "B"
    End With
    - but this produces a syntax error, presumably because you can have only one .Text line (or it won't accept <>?)
    I tried adopting the way of excluding chars when using the Like operator, and while it compiles, it will not replace
    any "A":
    With Selection.Find
    .Text = "A[!b#]"
    .Replacement.Text = "B"
    End With
    I suspect that I'm going to have to change tack completely in the way I'm doing this. Do you have any suggestions, please?
    The chord names/symbols are preceded/succeeded by either spaces or paragraph returns and can look like these, for example (all Font Bold and Underlined words only):
    C<sup>7</sup>
    Dm<sup>7</sup>
    Eb<sup>-5</sup>
    Bb<sup>+11</sup>
    F#m<sup>7</sup>
    i.e. [ABCDEFG][b # | optional][m |optional][- + | superscript, optional][2 3
    5 6 7 9 11 13 | superscript, optional]
    The crux of my problem is that the note A should be treated as entirely distinct from Ab or A# (and similar for other flattened/sharpened notes).
    Sorry for long post.

    Hi Ian,
    It is not easy to find Microsoft forums. However this forum is for the Visual Studio Net version. 
    Try this forum for VBA.
    https://social.msdn.microsoft.com/Forums/en-US/home?forum=isvvba
    Success
    Cor

  • Search and replace characters in a string

    I am very new to Sharepoint and need your help.  I have set up a calculated column in a sharepoint list that combines a IT release number to its Release title.  The list is set to appear on a calendar plus web part.  The idea is to show
    the title and release number of all deployments going to the field on a particular day.  The issue is that the release number has a bunch of zero's in it that I do not need to be displayed.  For example a release number could be "RND000000123456". 
    I need to parse out "D000000" so only "RN123456" along with its title show up on the calendar.  Please help!!

    Go here and search for "Remove characters":
    http://msdn.microsoft.com/en-us/library/office/bb862071(v=office.14).aspx
    From that page:
    Remove characters from text
    To remove characters from text, use the LEN, LEFT, and RIGHT functions.
    Column1
    Formula
    Description (possible result)
    Vitamin A
    =LEFT([Column1],LEN([Column1])-2)
    Returns 7 (9-2) characters, starting from left (Vitamin)
    Vitamin B1
    =RIGHT([Column1], LEN([Column1])-8)
    Returns 2 (10-8) characters, starting from right (B1)
    You could also try the REPLACE function:
    http://office.microsoft.com/en-us/windows-sharepoint-services-help/replace-function-HA001161055.aspx
    Brandon Atkinson
    Blog: http://sharepointbrandon.com

  • Find and replace characters in file names

    I need to transfer much of my user folder (home) to a non-mac computer. My problem is that I have become too used to the generous file name allowances on the Mac. Many of my files have characters such as "*" "!" "?" and "|". I know these are problems because they are often wild cards (except the pipe). Is there a way that I can do a find and replace for these characters?
    For example, search for all files with an "*" and replace the "*" in the file name with an "@" or a letter? I don't mind having to use the terminal for this (I suspect it will be easier).
    Is this possible? Does anyone have any suggestions?
    Thank you in advance for any help you may be able to provide.
      Mac OS X (10.4.8)  

    Yep.
    "A Better Finder Rename" is great for batch file renaming.
    http://www.versiontracker.com/dyn/moreinfo/macosx/11366
    Renamer4mac may be all you need.
    Best check out VersionTracker. In fact everybody should have this site bookmarked and visited daily.
    http://www.versiontracker.com/macosx/

  • Replace characters in a string

    Hi,
    I need to replace all occurrences of control characters except space,newline,tabs in a string . I can give a replace statement for each of these characters but I want to avoid this by making use of regular expressions. Can anyone help me in this regard.
    I tried using the following replace statements with regular expression, but i am not getting the required results:
    replace all occurrences of REGEX '[[:cntrl:]]' in lv_char with space replacement count lv_count_r.
    ---> this replaces even the spaces
    replace all occurrences of REGEX '[[:cntrl:]][^[:space:]]' in lv_char with space replacement count lv_count_r.
    --> this replaced even some alpha numeric characters
    Thanks and Regards,
    Shankar

    is there anyway to do this without using regular
    expressions.. regular expressions are the last
    solution for me..Remember that you can never really replace the characters of a String. Strings are immutable. Once created they cannot change.

  • Replace characters in chat text

    I was written a small applescript to replace some characters in chat message. Here is my code.
    property searchList : {"live"}
    property replaceList : {"love"}
    to switchText of t from s to r
       set text item delimiters to s
       set t to t's text items
       set text item delimiters to r
       tell t to set t to beginning & ({""} & rest)
       t
    end switchText
    to convertText(t)
       set d to text item delimiters
       considering case
           repeat with n from 1 to count searchList
               set t to switchText of t from my searchList's item n to my replaceList's item n
           end repeat
       end considering
       set text item delimiters to d
       t
    end convertText
    using terms from application "Messages"
       on message sent theMessage for theChat
           try
               return convertText(theMessage)
           end try
       end message sent
       on message received theMessage from theBuddy for theChat
           return convertText(theMessage)
       end message received
       on chat room message received theMessage from theBuddy for theChat
           return convertText(theMessage)
       end chat room message received
    end using terms from
    This code worked fine for Yahoo account, but it dont work when i received messages from iMessage and Jabber account. I tried to look into Alerts event and i found "Message received in active chat" ,maybe iMessage and Jabber account use this event to alert received message, but the problem is this object not defined in applescript. How can i define it, or make this code work with  iMessage and Jabber account.

    after long long times for google and test myseft, i found yahoo account have problem too, because active chat why is apple dont define this object ""Message received in active chat"'

  • Replacing characters in a string

    I have an application where a user can enter information into a webform. I'm using JSP, but of course the backend there is a Java function also.
    I am trying to write a function which will replace when the user hits enter with a <br> (break tag).
    Right now it's a complicated, messy loop to look at each character and it has many flaws.
    Is there a "replace" function that will do this for me?
    However, I don't think in a webpage form it transfers the \n end of line characters.

    Nope compiler error
    symbol : method replaceAll (java.lang.String,java.lang.String)
    location: class java.lang.String
    return (txt.replaceAll("\n","<br>"));

  • Replacing characters in a string - URGENT!

    Hi guys
    I have a string - 003452.jpg.xml
    I want to remove the '.jpg'
    How do I do this ... I was using :
    String image1 = 002452.jpg.xml;
    String newString = image1.replace ( '.jpg',' ' );
    What am i doing wrong???
    thanks

    The replace method takes characters as its arguments not strings. If you files will always be in that format you can do something like:
    In j2se 1.4 a replace based on regular expressions was added so you could use:
    String image1 = "002452.jpg.xml";
    String newString = image1.replaceAll ("\\.jpg", "" );

  • Replace characters between with single * in variable

    Hi Experts ,
    I want to replace all characters between <  > with *. Data is stored in variable type char255.
    Example ,
    Suppose variable contains : Wage Type <Wage Type> Not Valid For Interface ID <ID>
    I want output as Wage Type * Not Valid For Interface ID *.
    Thanks & Regards ,
    Jigar Thakkar

    Hi Jigar,
    Find the length of the string and use DO...ENDDO statement. Inside the loop, didnt consider the text between < and > and move to another string and add * when  > is encountered in the string.
    data:
      gv_len type i,
      gv_str type string value 'Wage Type <Wage Type> Not Valid For Interface ID <ID>',
      gv_rep_str type string,
      gv_flag type char1,
      gv_index type sy-index.
    gv_len = strlen( gv_str ).
    do gv_len times.
    gv_index = sy-index - 1.
    if gv_str+gv_index(1) = '<'.
    gv_flag = 'X'.
    continue.
    elseif gv_str+gv_index(1) = '>'.
    clear gv_flag.
    concatenate gv_rep_str '*' into gv_rep_str.
    continue.
    elseif gv_flag is initial.
    concatenate gv_rep_str gv_str+gv_index(1) into gv_rep_str.
    endif.
    enddo.
    write:/ gv_rep_str.
    Thanks,
    Vinay
    Edited by: Vinaykumar G on May 29, 2009 8:04 PM

  • Replacing Characters in File

    Ok, here is my situation. I am using a 3rd party application to upload files to my server. I am using another 3rd party application to index and search the files. The problem I am having is that the searching application will only recognize files without spaces in them, and most of the 3500 files that are going to be uploaded have spaces in them and I don't want to have to go through all of the files and rename them. What I am trying to do is to replace the space with an '_'. Here is the code that does the uploading.
    <%
                  Hashtable files = mrequest.getFiles();
                    if ( (files != null) && (!files.isEmpty()) )
                        UploadFile file = (UploadFile) files.get("uploadfile");
         String filename = file.getFileName();
         pageContext.setAttribute("filename", filename);
                        // Uses the bean now to store specified by jsp:setProperty at the top.
                        upBean.store(mrequest, "uploadfile");
    %>I know there is the replace(char,char) but I can't seem to get this to work. Any help would be greatly appreciated.

    The replace commond itself is fairly simple
    filename = filename.replace(' ', '_')
    But you have to tell it to save the file using this new name.
    is that what the pageContext setAttribute() call was for?
    You might have to do
    file.setFileName(filename);
    Is this hashtable a table of all the files? Then you need to iterate through the map and update each entry.

  • Replace Characters in a Text Field

    Hello,
    I have a script to replace a carriage return in a text box.
    The script is not working when run from the console.
    Can any one please advise how the script can be revised to find/replace a carriage return in a multiline text box?
    var t = this.getField("ActionAgenda").value;
    t = t.replace("\r","") // delete carriage return
    Any assistance would be most appreciated.

    Thank you for your help, George.
    The script works perfectly to replace carriage returns in a text field.
    Can you please advise how to modify the same script to remove a blank line instead of a carriage return?
    Thanks again, George.
    Regards
    Jo

Maybe you are looking for

  • Please help - need to import/create song snippets in iMovie

    Hi - I'm making a movie in '06 HD which requires a series of short (apx. 1 minute each) song segments taken from longer songs (apx 4 minutes each). After learning how to first crop the song in iTunes, I could not figure out how to import just the cro

  • ORA-23401: materialized view ""SYS"".""MV_OPTIONS"" does not exist

    Oracle 11gR1 Linux Red Hat 6.3 I have never seem this object SYS.MV_OPTIONS before much less know why it would be missing. Any ideas? I can no longer refresh my materialized views.

  • Windows 7 No 5GHZ WiFi on Mac Mini A1347 2010 Model using BootCamp

    I have a new 2010 model mac mini and the WiFi in snow leopard works fine with both a 2.4GHZ and a 5GHz connection. When I reboot into Windows 7 I am only able to use a 2.4GHz connection and the 5GHz connection does not even show up as an option to co

  • CS5 animation symbol replacement question....

    Sooo, my company (FB games) has fired everyone who knew what they were doing leaving me, with no knowledge of flash, staring at my to-do list near tears, unable to complete basic tasks. I need to take an existing walk cycle animation and replace the

  • Can't Finish Sync to 3rd Gen iPod

    I have a 3rd Gen 15 GB iPod. My problem is that I can't finish syncing the iPod because I have a laptop with 4-pin Firewire, so the iPod battery dies in the middle of syncing to iTunes. When I look at the iPod only three songs have been transfered ev