Error replacing strings with \ in them

I get the following error:
Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException
: String index out of range: 1
        at java.lang.String.charAt(Unknown Source)
        at java.util.regex.Matcher.appendReplacement(Unknown Source)
        at java.util.regex.Matcher.replaceAll(Unknown Source)
        at java.lang.String.replaceAll(Unknown Source)
        at Main.runCommand(Main.java:106)It occurs in the following for loop of my program:
String tshow = "";
            for(int i = 1; i < org.size(); i++) {
                tshow += " " + org.get(i).replaceAll("\\s", " ").replaceAll("\\n", "\n").replaceAll("\\\\", "\\");;
            }If I do not use a \ (which is placed in the vector org) then everything runs fine. But if I just place one \, even if I don't type \n or \\ or \s, then it throws that error.
For example, if org.get(1); is "blah\", then the error will be thrown.
Why does this happen? I can change the \\ to / instead, but I don't understand.

Here is some more of my code to show you why i set i equal to 1:
       String comm = org.get(0);
        System.out.println(org.get(1));
        if(comm.equals("run")) {
            fileRun(org.get(1));
        } else if(comm.equals("print")) {
            String tshow = "";
            for(int i = 1; i < org.size(); i++) {
                tshow += " " + org.get(i).replaceAll("\\s", " ").replaceAll("\\n", "\n").replaceAll("\\\\", "\\");;
            ios.showText(tshow);
        }

Similar Messages

  • How to replace string with image( Say Smiley).........????

    Hello To All Experts !!
    I wanna looking for some help in displaying image in my text area when should i type ":)" in text field.....
    I got some program through forums....
    import java.util.*;
    import javax.swing.ImageIcon;
    public class TokenizeSmiley {
        private static final HashMap SMILEYS;
        static {
            SMILEYS = new HashMap();
            SMILEYS.put(":)", new ImageIcon("images/1.gif"));
            SMILEYS.put(";)", "<wink>");
        public static void main(String[] args) {
            String text = "Hello!! :) How are you ;)";
            StringTokenizer st = new StringTokenizer(text);
            String token;
            while (st.hasMoreTokens()) {
                token = st.nextToken();
                if (SMILEYS.containsKey(token))
                    token = (String)SMILEYS.get(token);
                System.out.print(token + " ");
    }but it is showing <smile> and <wink> as it is given...i tried to give path of image ...but it is nt fetching then also.....
    Plz help in this....
    Message was edited by:
    Damz@del

    So your data is stored in XML. So what? You haven't asked a question about the XML or how to format it or how to access it. You asked a question that had nothing to do with XML at all. It's as if you said "My data is stored on a Windows computer so I will call Microsoft's support line to ask them this question."
    And I can't even suggest a suitable forum because a "text area" could be an AWT component or an HTML component. But I do suggest you ask in the right place.

  • Replace string with regular expression

    I am new to the regular expression. I am just trying to remove double quotes from a string.
    My sample string is sql statement(SELECT "SCHEMA"."TABLE1"."COLUMN1", "SCHEMA"."TABLE1"."COLUMN2" FROM "SCHEMA"."TABLE1", "SCHEMA"."TABLE2" WHERE "SCHEMA"."TABLE1"."COLUMN1" = "SCHEMA"."TABLE2"."COLUMN1" );
    This is what I came up with.
    String s = query.replaceAll("\\.\"", ".").replaceAll("\"\\.", ".").replaceAll("\\s\"", " ").replaceAll("\\s\"", " ").replaceAll("\",", ",").replaceAll("\"\\s", " ");
    But I want to optimize this line.
    Could anybody tell me how to call replaceAll once with using regular expression instead of calling replaceAll multiple times? Some table or column names can have double quotes, so I want to remove the double quotes without replacing the double quotes which is part of the table or column name.
    I'd appreciated it.

    caesarkim1 wrote:
    I am new to the regular expression. I am just trying to remove double quotes from a string.
    My sample string is sql statement(SELECT "SCHEMA"."TABLE1"."COLUMN1", "SCHEMA"."TABLE1"."COLUMN2" FROM "SCHEMA"."TABLE1", "SCHEMA"."TABLE2" WHERE "SCHEMA"."TABLE1"."COLUMN1" = "SCHEMA"."TABLE2"."COLUMN1" );
    This is what I came up with.
    String s = query.replaceAll("\\.\"", ".").replaceAll("\"\\.", ".").replaceAll("\\s\"", " ").replaceAll("\\s\"", " ").replaceAll("\",", ",").replaceAll("\"\\s", " ");
    ...Note that the following two lines are equivalent:
    s = s.replaceAll("a","").replaceAll("b","");
    s = s.replaceAll("a|b","");

  • How to replace string with image( Say Emoticons )??

    Hello Friends !!
    I am working on chat messenger and want some help in "How to access Emoticons when somebody typed :), ;), :)) and many more strings.....?"
    Is there any sample code to do that job or any function to perform such task??
    Thanks in Advance....

    use event listener... found match, load image instead of text on the fly.

  • Can I replace string with a variable in innerhtml?

    Hi,
    I have the following script:
    function change2(e)
    var userInput = document.getElementById(e).innerHTML;
    userInput++;
    document.getElementById(e).innerHTML = userInput;
    </script>
    being called via:
    echo "<a href=\"#\"><img src=\"./../Up.JPG\" border=\"0\" onclick=\"change2('".$idkey."');\"></a>";
    echo " ".$num_rows1."</form>";
    I basically want 'e' to be dynamic accepting the id passed into it.
    Thanks in advance.

    sorry, had a typo. resolved.

  • Failure to read multiline string with Read Key.vi

    I converted 2D array into a spreadsheet string and attempetd to write it as a key value into a configuration file. This worked just fine. However, when I attempted to read this multiline string using Read Key.vi, I got just the first line in return (see two vi's attached).
    As sufficient documentation on configuration file vi's is all but missing, could you please advise on their (undocumented) features? What do I miss?
    Thank you.
    Michael
    Attachments:
    Save_2D_array_in_config_file.vi ‏29 KB
    Read_2D_array_from_config_file.vi ‏31 KB

    Hi Michael,
    MichaelS wrote in news:506500000008000000F7980000-
    [email protected]:
    > I converted 2D array into a spreadsheet string and attempetd to write
    > it as a key value into a configuration file. This worked just fine.
    > However, when I attempted to read this multiline string using Read
    > Key.vi, I got just the first line in return (see two vi's attached).
    I use Config files all the time. Much more user-friendly than the
    Registry. They are a Microsoft thing really, rather than LabView, and
    come from Windows 3.11. Each value is limited to one line, so when you
    write a spreadsheet string with end-of-line characters in it, you're
    effectively breaking the .inf file
    The solution? Try putting a "Search and Replace String
    " after your
    "Array To Spreadsheet String". Wire "Replace All" with a TRUE constant,
    and wire "Search String" with a string in "\" view and enter \r\n (or do
    0A0D in Hex view) and then then wire Replace String with a ";"
    Now your .inf file will look like:
    [Array]
    Data=1.0000,0.0000,0.0000;0.0000,2.0000,0.0000;0.0000,0.0000,3.0000;
    When reading it, just reverse the search and replace strings above.
    I hope this helps,
    Andrew

  • Error 'INK CARTRIDGE ERROR REPLACE CARTRIDGE' on EPSON Stylus Pro 9700

    I have removed the printhead and clean it with a cleaning solution. I have already done it 2 or 3 times before and had no issues but this time I am getting this error message 'INK CARTRIDGE ERROR REPLACE CARTRIDGE' with all the cartridges flashing on the front panel. If I remove any one cartridge and turn the printer on it recognize all the other cartridges apart from the one I have removed and ask me to installed the missing cartridge. After installing the missing cartridge I get the same error again.
    Any help will be much appreciated.
    This topic first appeared in the Spiceworks Community

    Update or reinstall the EPSON software.

  • Changing the cursor theme in LXDE? (bonus: issues with icon themes)

    Hey all.
    I was looking for a simple method to do this and am totally failing. Searching LXDE and "cursor theme" doesn't get me much so I was looking at how to do it in Openbox. That involves editing the .Xdefaults file which I didn't have, and upon creating one threw everything to hell.
    I was poking at the ~/.config/LXDE/config" file and noticed it had things outlined such as my icon theme and GTK theme, but saw no option for X11 cursor. Is there somewhere for that?
    BTW, I'm sorry if I've been stupid lately with questions, I only just signed up after figuring I'd stay off the forums until I had my system 99% complete on my own and now I feel like I'm asking overly basic stuff, but honest injun I do a lot of searching before I post.
    Last edited by SomeGuyDude (2008-10-13 01:20:40)

    wimac wrote:
    try putting:
    export XCURSOR_THEME="Bluecurve"
    in your ~/.config/openbox/autostart.sh
    replace Bluecurve with the theme of your choice and restart X that should do it...
    There isn't any such file. ~/.config/openbox just has a "lxde-rc.xml" in it.
    fwojciec, that worked. Thanks a million. Looks like I'm juuuuust about set on this thing. A few more hiccups to figure out and I'll be golden (all related to cosmetics).

  • Search and Replace String throwing the wrong error message with regexp?

    This came up in a LAVA thread, and I'm not sure if there's a bug here or not. When using Search and Replace string, and using a regular expression of [(G[b|i])], LabVIEW throws error -4622, "There is an unmatched parenthesis in a regular expression."  There are obviously no unmatched parenthesis in that expression, so it seems to me that the wrong error is being thrown. I'm just not sure if that's a syntactically valid regexp. The problem seems to be with nesting [ ]'s inside ( )'s inside [ ]'s. I've tried a couple of regexp resources on the Web, and one suggests it's valid, while the other seems to think it isn't.
    Message Edited by eaolson on 03-13-2007 10:33 AM
    Attachments:
    ATML_StandardUnit2.vi ‏10 KB
    regexp.png ‏5 KB

    adambrewster wrote:
    I think your regexp is invalid.
    In regexps, brackets are not the same as parentheses.  Parens are for grouping, while brackets are for matching one of a class of characters.  Brackets can not be nested.
    If the regexp is replaced with [G[bi]], there is no error, so it's not a matter of nested brackets. I couldn't find anything on the PCRE man page that forbids nested brackets specifically, but it makes sense.
    Your expression "[(G[bi])]", therefore parses as a character class which matches '(', 'G', '[', 'b', or 'i' followed by an unmatched paren, and an unmatched bracket.
    I don't believe that's the case. Replace the regexp with [(Gbi)], and the error goes away. So it's not a matter of the '(' being literal, and then encountering a ')' without a matching '('.
    daveTW wrote:
    what string exactly you want to replace? I think the round braces are not right in this case, since they mark partial matches which are given back by "match regular expression". But you don't want to extract parts of the string, you want to replace them (or delete, with empty <replace string>). So if you leave the outer [( ... )] then your RegEx means all strings with either "Gb" or "Gi".
    It's not my regular expression. A poster at LAVA was having problems with one of his (a truly frightening one), and this seemed to be the element that was causing the problem. I'm pretty sure that the originator of the regexp meant to use G(b|i), which seems like a complicated way of matching "Gb" or "Gi", if you ask me.

  • CF8 string replacement of \ with ' generates errors ?

    Hello,
    I have been banging my head on this CF8 issue for too long now.   I have a string that
    is of the form [~]'trespes[~] where I need to replace [~] with the escaped backslash
    &#92;   I have tried coldfusion replace, and java ReplaceAll but whenever I put any
    escaped html into the fuction, replace(string,"[~]","&#92;") I get an error from CF
    Missing argument name. When using named parameters to a function,
    every parameter must have a name.
    If I use java ReplaceALL I get the same result.  Any insight to this problem would
    be greatly appreciated, driving me batty..   I know it must be simple..  ugh.
    Thanks,
    Bob

    http://help.adobe.com/en_US/ColdFusion/10.0/Developing/WSc3ff6d0ea77859461172e0811cbec0999 c-7ffb.html
    The docs are for CF10, but it's the same in CF8.
    Adam

  • [JS - CS3]  Can't REPLACE A with B within a string? Help Please...

    Hello Experts,
    First off - I'm a newbee to all this JS and especially with CS3.
    I have a string: '
    b myDocumentName
    which can have it's value as: '
    b 00000en_ Generator WX/WY
    Problem is, backshlashes ( / )are a bad thing for me...
    b Question:
    How can I do a 'replace' operation to replace the '/' from the string with a '_'?
    I have at the moment:
    > var myDocSaveName = oneResult[3]+oneResult[4]+oneResult[5];
    > myDocSaveName.replace(what "/", with "");
    > myDoc.save ("C:/DATA/"+myDocSaveName, undefined, undefined, true)
    I get an error Nr. 25... Offending text:"/"
    What am I doing wrong?

    'what' and 'with' are the names of those arguments. They should not be included in the statement:
    myDocSaveName.replace("/", "");
    But that still won't work because replace doesn't operate on a string in situ, it returns the modified string. So:
    myDocSaveName = myDocSaveName.replace("/", "");
    This too has its limitations. It'll change only the first instance of "/", not all of them. To change all of them, you need to restate the 'what' as a RegExp:
    myDocSaveName = myDocSaveName.replace(/\//g, "_");
    A RegExp literal is delimited by the "/" character, so to have it, alone, as the character to be sought you must use the backslash to escape the character. Then, to indicate you want the replace to happen globally within the string, you add the 'g' after the RegExp.
    Dave

  • 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

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

  • My 5th gen. ipod died and they replaced it with a new one, but I'm having problems getting the music. An error message says that its not authorized on this computer. The ipod is synced but it wont let me add what music I want.

    My 5th gen ipod died and apple replaced it with a new one. I synced it up to the itunes that I already have on my computer but an error message keeps coming up telling me that its not authorized on this computer. What do I do?

    About iTunes Store authorization and deauthorization
    iPod: Troubleshooting songs and audiobooks that won't play
    iPod does not play content purchased from the iTunes Store

  • After soak test update, I get error messages repeatedly. The majority are "unfortunately, messaging has stopped", but you can replace messaging with "android os", or any other process, as it happens with more than just messaging. I have had numerous peopl

    After soak test update, I get error messages repeatedly. The majority are "unfortunately, messaging has stopped", but you can replace messaging with "android os", or any other process, as it happens with more than just messaging. I have had numerous people call and ask why I didn't reply to their texts...and I look, but have not received any new texts. YES, I have restarted phone. I have cleared data as well as cache on all apps. I have downloaded the vzw messaging app, which seems silly, since it happens with several different processes and apps, but all to no avail. I am missing texts from my employer, from my family. This did happen, but rarely, before this "soak test". It is now Kitkat version 19.6.3.obake_verizon.en.US. THIS is when I started having problems...like 50 times a day kind of problems! I have seen hundreds of posts all over the internet over the past 3 days. Does no one know how to fix this??? Shouldn't there be a way to revert phone to a pre-update state? and no, hard reset did NOT work!!!! I have been with verizon for well over 15 years, but I have not upgraded my lines and will not in July either. This is ridiculous. It's not like my games aren't working, it is my messaging and "android os"...my lifeline at work!

    kristinaf333,
    Oh no, I am sorry to hear your messages are not working since the software update. I greatlly appreciate doing all that troubleshooting to try and get the messaging application back in business. I know how much I rely on my messages so I can understand the urgency to get this resolved. Have you had a resolution ticket opened since you started experiencing issues with your messages? Does this happen with all contacts or just some? Please provide additional information to ensure we get to the bottom of this for you.
    KarenC_VZW
    Follow us on Twitter @VZWSupport

Maybe you are looking for

  • FBL3N Line Item Report

    Hi Everybody, I want the display of Network /Activity coloumn for the line items posted on some network.I checked in standard report FBL3N here i can able to select the WBS element coloumn to change the existing layout but there is no option for sele

  • F110 - error in executing

    Dear All,                I am facing a problem while executing F110. The system posts some of the vendor and leave out other vendor e.g. if I have 500 line items, the system picks only 40 or 50 and the remaining is shown as running. When I check the

  • ActionListener&MouseListener add to Drawing Object in JApplet

    hi,guys When I am doing my JApplet, I wanna add the ActionListener and MouseListener to the Drawing Object... Like this: Graphics2D g11 = (Graphics2D)g; g11.setColor(Color.orange); g11.fillOval(10,300, 100, 40); g11.setColor(Color.darkGray); g11.draw

  • QA Testing and transport to PROD

    Can anyone explain in detail the steps involved in QA testing till transport to PROD. objects are : new report , new table , zFM Is there anything specific to be done in QA for new tables.Or it can simply be transported. Is there anything to be done

  • Java applications

    i hv a question,why do i get this error Exception in thread "main" java.lang.NoClassDefFoundError: jas Press any key to continue . . . whenever i run an application? i try 2 run an applet and it works,but working with JFrame & applications doesn't wo