Not sure I am having StringIndexOutOfBondException

Hi Fox!
I am trying to write a simle code. In my Code I just copy values from Stringbuffer to String. Then delete everything from Stringbuffer and use String in the next block of code. I am not sure why I am having StringIndexOutOfBondException. What?s wrong with my String? Can anybody tell me?
Here is my Code
    String s1 = "one cat two cats in the yardcat according to the above terms accordingly.";
    System.out.println(s1);
    Pattern p = Pattern.compile("above",Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(s1);
    StringBuffer sb = new StringBuffer();
    System.out.println("This is in our buffer..."+sb.toString());
    while (m.find()) {
      m.appendReplacement(sb, "");
    m.appendTail(sb);
    System.out.println("This is in our buffer NOW ..."+sb.toString());
    String test = sb.toString();
    System.out.println("In test copy from buffer---"+test);
    sb.delete(0,sb.length());
    System.out.println("This is in our buffer FINALLY ..."+sb.toString());
   // works fine till here
    s1=test;
    System.out.println(s1);
// in this block i get acception.
    Pattern p1 = Pattern.compile("according",Pattern.CASE_INSENSITIVE);
    Matcher m1 = p.matcher(s1);
    while (m.find()) {
      m.appendReplacement(sb, "");
    m.appendTail(sb);
    System.out.println("This is in our buffer NOW ..."+sb.toString());
    test = sb.toString();
    System.out.println("In test copy from buffer---"+test);Thanks in advance

Hi Guys,
I'm not familiar with Pattern and Matcher, so I thought I would try compiling this and see what I can learn by attempting to fix it. Problem is, it compiled and ran fine for me, no errors....
Maybe I am completely missing something?
"one cat two cats in the yardcat according to the above terms accordingly.
This is in our buffer...
This is in our buffer NOW ...one cat two cats in the yardcat according to the terms accordingly.
In test copy from buffer---one cat two cats in the yardcat according to the terms accordingly.
This is in our buffer FINALLY ...
one cat two cats in the yardcat according to the terms accordingly.
This is in our buffer NOW ... terms accordingly.
In test copy from buffer--- terms accordingly.
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class StringError
     public static void main(String[] agrs)
          String s1 = "one cat two cats in the yardcat according to the above terms accordingly.";
           System.out.println(s1);
           Pattern p = Pattern.compile("above",Pattern.CASE_INSENSITIVE);
           Matcher m = p.matcher(s1);
           StringBuffer sb = new StringBuffer();
           System.out.println("This is in our buffer..."+sb.toString());
           while (m.find()) {
                m.appendReplacement(sb, "");
           m.appendTail(sb);
           System.out.println("This is in our buffer NOW ..."+sb.toString());
           String test = sb.toString();
           System.out.println("In test copy from buffer---"+test);
           sb.delete(0,sb.length());
           System.out.println("This is in our buffer FINALLY ..."+sb.toString());
           // works fine till here
           s1=test;
           System.out.println(s1);
           // in this block i get acception.
           Pattern p1 = Pattern.compile("according",Pattern.CASE_INSENSITIVE);
           Matcher m1 = p.matcher(s1);
           while (m.find()) {
           m.appendReplacement(sb, "");
           m.appendTail(sb);
           System.out.println("This is in our buffer NOW ..."+sb.toString());
           test = sb.toString();
           System.out.println("In test copy from buffer---"+test);
}

Similar Messages

  • Have been a Verizon customer since I got my first cell phone in my 30's - I am 50 now! A year ago, I stupidly opted to get a new phone on the EDGE program because I was trying my first Samsung device and was not sure I would like it having been an IPhone

    have been a Verizon customer since I got my first cell phone in my 30's - I am 50 now! A year ago, I stupidly opted to get a new phone on the EDGE program because I was trying my first Samsung device and was not sure I would like it having been an IPhone user for years.I was right! Or so I thought.... The Note 3 has been horrible. I am on my second phone(replaced it under warranty) and it still freezes, shuts off on its own, and will not come back on for long periods of time. Having had enough, I decided to EDGE Up to another device. On March 16th I tried to edge up my device online but was unable to. I immediately called to figure out what the problem was. Back in October I had a mix up in my billing where I had set up a payment. It was not done properly by customer service and as a result my line was cut off. I called the EXACT day it went off, filed a complaint about the lack of follow through for my arranged payment, and thought I had it straightened out as the payment was made that same day. That incident, although it was a Verizon error, caused my Edge Contract to be "hotlined". I spent an hour on the phone on March 16th clearing the whole mess up. When the conversation ended, the Verizon representative admitted it was a Verizon error, documented everything, and then told me she was filing a release for the hotline hold that would take a couple of days. Her name was Linda and I stupidly trusted what she said.
    The days passed as I prepared to have a major foot surgery and to get my classroom straight before I would be out recovering for 3 weeks. All the time, my Samsung continued to glitch out like it has since I got it! While sitting on the couch recovering, I decided to deal with the phone issue again and EDGE UP. I figured 10 days latter, Linda would have taken care of the issue. Unfortunately, I faced the same problem and was told it was not eligible to edge up at this time. BACK on the phone again, 2 supervisors, 3 customer service reps. ( JOE from New York being the rudest customer service rep. I have EVER worked with) and 4 frustrating HOURS latter, Jason, the equally rude supervisor from Rochester, New York, informed me that Linda gave me BAD information, there was NOTHING he could do, and I am NOT eligible until April 14th!!!!! The WORST experience I have EVER had with a company. They were completely inept, rude, and not concerned about my time, my frustration, or the problems I was facing with their product in the LEAST. I have 4 LINES on Verizon that I am going to talk to Sprint about buying out. It was a horrible experience, and I can NOT believe I have no recourse or anyone to talk to....

    Edge has very clear restrictions, one being that you must have 6 months of clean payment history which you don't. Either wait until April 14, or good luck at Sprint.
    I am unsure how it can be determined the payment mix up was the fault of CS, but regardless, the mix up was done. There can be any number of reasons why a payment could be missed without any fault on your part, however you are still the responsible party for the account and must live with the repercussions.

  • I'm having problems (1)selecting onscreen text, (2) having problems resizing menu boxes and selecting menues with the cursor. I'm not able to select menus and move them. I'm not sure how to correct this.

    I'm having problems (1) selecting onscreen text, (2) resizing menu boxes and selecting menues with the cursor. I'm not able to select menus and move them. I'm not sure how to correct this.

    1) This is because of software version 1.1. See this
    thread for some options as to how to go back to 1.0,
    which will correct the problem...
    http://discussions.apple.com/thread.jspa?threadID=3754
    59&tstart=0
    2) This tends to happen after videos. Give the iPod a
    minute or two to readjust. It should now be more
    accurate.
    3) This?
    iPod shows a folder icon with exclamation
    point
    4) Restore the iPod
    5) Try these...
    iPod Only Shows An Apple Logo and Will Not Start
    Up
    iPod Only Shows An Apple Logo
    I think 3,4, and 5 are related. Try the options I
    posted for each one.
    btabz
    I just noticed that one of the restore methods you posted was to put it into Disk Mode First rather than just use the resstore straight off, I Have tried that and seems to have solved the problem, If it has thank you. previously I have only tried just restoring it skipping this extra step. Hope my iPod stays healthy, if it doesnt its a warrenty job me thinks any way thanks again

  • I'm having issues loading Youtube on my MacBook Pro for about a week now.  I'm not sure if this is because of my computer or internet but my sister's PC loads Youtube completely fine.  Can someone help me figure this out?

    I'm having issues loading Youtube on my MacBook Pro for about a week now.  I'm not sure if this is because of my computer or internet but my sister's PC loads Youtube completely fine.  Can someone help me figure this out?

    Hi, I had been having the same problem for over a week, but both my window's HP and my 2011 macbook pro barely could load youtube.  What kind of router you have?  I was using a belkin play router that was only 8 months old, switched to a new AirPort Extreme Base Station and now everything works perfect.

  • Hi.  I am having issues with copying files to my shared WB 2TB HDD connected to my airport extreme.  Comes up with error 50.  I am using a Macbook Pro to copy from so not sure what I am doing wrong.  Can someone help? thanks Rory

    Hi.  I am having issues with copying files to my shared WB 2TB HDD connected to my airport extreme.  Comes up with error 50.  I am using a Macbook Pro to copy from so not sure what I am doing wrong.  Can someone help? thanks Rory

    These links might provide some information that may be of help.
    http://support.apple.com/kb/TA20831
    https://discussions.apple.com/message/2035035?messageID=2035035
    I've encountered this error myself upon occasion.  If I remember correctly, it was a permissions/ownership issue with the some of the files I was copying.

  • I bought  my MacBook Pro in 2010. This is the first Mac I have owned and recently it is having some difficulty loading we pages, often timing out. This Mac environment is entirely different for me and I am not sure where to begin troubleshooting/clean-up.

    I bought  my MacBook Pro in 2010. This is the first Mac I have owned and recently it is having some difficulty loading we pages, often timing out. This Mac environment is entirely different for me and I am not sure where to begin troubleshooting and/ or clean-up. I have moderate computer skills and try not to download or access questionable material, however recently I visited the Ap Store and purchased a couple of different aps to use in record keeping and for making a flyer. I am not even sure how to remove these programs to see if it helps.
    Any tips or tricks are appreciated.
    Thank you!

    Time to see about the PRAM battery.
    By the way iOS and OS X are different systems.
    iOS is the operating system for iPads, iPhones, and iPod touch.
    Mac OS X is the operating system for Mac labelled computers.

  • I have purchased a new iPad2 and I was wondering if there is a way to get iPod content onto this new device. I am having difficulty finding any information on this kind of transfer and I am not sure if it is even possible. Thanks

    I have purchased a new iPad2 and I was wondering if there is a way to get iPod content onto this new device. I am having difficulty finding any information on this kind of transfer and I am not sure if it is even possible. Just not looking forward to loosing my progress in games and information in notes and other apps. Thanks

    Have you been syncing the iPod with iTunes? Then you just connect the iPad and set it up through iTunes and sync any content you want onto it.
    http://support.apple.com/kb/ht1386
    In terms of games/apps. If they are not universal (you will see a + symbol next to them) or made for iPad (you would see an HD in the name, usually) then they won't look good on an iPad as those apps will open in a iPod sized window, giving you the option to enlarge.

  • TS3212 Having problems downloading. OS is LINEX and I'm not sure how to load itunes with it.

    Having problems downloading. OS is LINEX and I'm not sure how to load itunes with it.

    Agreed. No native linux support. The only ways you could run iTunes with a primary linux system would be to a) dual boot, b) virtualize Windows with VirtualBox, VMware, etc., or c) attempt to run iTunes in Wine (which doesn't usually work very well). Dual boot would give you the benefit of complete support and usage of hardware and software, but virtualizing is a bit more convenient, since you would not have to reboot your linux host.

  • TS3074 Hello anyone with Windows 7, not sure why having followed instructions above, install of latest version of itunes won't work and can no longer open old version either.  anyone help with this?

    Hello anyone with Windows 7, not sure why having followed instructions above, install of latest version of itunes won't work and can no longer open old version either.  anyone help with this?

    Hi,
    thanks for your reply.
    Yes, except n°1 - empty Temp directory, I had tried/checked all of those.
    I emptied the local temp folder tonight, but it still won't work.
    Please note: the installation doesn't give me any problem. The program was working fine, until at one point *plouf* it stopped working. I can re-install it without any problem, it just crashes when opening.
    \\edit\\ I seem to have located the problem, it's in the library files. If I re-install iTunes without my library, it works fine (though there is no music in it, yet). As soon as I import my library, or replace the My Music\iTunes folder with the old one, it stops working.

  • I am having trouble installing photoshop Lightroom.  I have the S/N #... I need it to be confirmed and activated so i can receive an email to activate the system to my computer.  I am not sure how to go about doing so.

    I am having trouble installing photoshop Lightroom.  The program is installed and has some sections blocked off.  I have the S/N #... I need it to be confirmed and activated so i can receive an email to activate the system to my computer.  I am not sure how to go about doing so. 

    If you have a serial number, you simply need to enter it into the proper fields.
    Since you don't say what version of Lightroom, and what sections are "blocked off", let me guess that you have Lightroom CC, and you need to enter the serial number to turn it into Lightroom 6. Here are the instructions: Adobe Photoshop Lightroom Help | Serialize Lightroom CC trial to activate as Lightroom 6
    And if that's not the right assumption, then please give us the details.

  • Hello, I am having issues open very large files I created, one being 1,241,776 KB. I have PS 12.1 with 64 bit version. I am not sure if they issues I am having is because of the PS version I have, and whether or not I have to upgrade?

    Hello, I am having issues open very large files I created, one being 1,241,776 KB. I have PS 12.1 with 64 bit version. I am not sure if they issues I am having is because of the PS version I have, and whether or not I have to upgrade?

    I think more likely, it's a memory / scratch disk issue.  1.25 gigabytes is a very big image file!!
    Nancy O.

  • Problems installing IWork Pro 9.0.3 Not sure where to place my question but I'm having problems installing iwork 9.0.3

    Not sure where to place my question but I'm having problems installing iwork 9.0. My MacBook Pro doesn't read the disk and ejects after a minute. I just bought the mac and iwork. Any thoughts?

    https://discussions.apple.com/community/iwork

  • Why all of a sudden am I having difficulty sending Gmail emails? I get a send error. When I run diagnostics there is a SMTP and IMAP account for Gmail and I am not sure how to fix this.

    Why all of a sudden am I having difficulty sending Gmail emails? I get a send error. When I run diagnostics there is a SMTP and IMAP account for Gmail and I am not sure how to fix this.

    Hi jodilynnf,
    When using Connection Doctor to see what is could be causing the issue, look for the red dots to let you know what is wrong. Then all you have to do is correct that information. You can double click on the section that is giving you issue and it will take you there. Most issues could be just password being entered incorrectly. Take a look at the article below to walk you through troubleshooting issues with Mail.
    OS X Mail: Troubleshooting sending and receiving email messages
    http://support.apple.com/en-us/TS3276
     Take it easy,
    -Norm G.

  • Having trouble adding my Mac Pro Tower to my Apple ID  not sure why it does not work

    Having trouble adding my MacPro Tower to my Apple Id will not allow me to download the music and videos I purchase on my Iphone or IPad... Very frustrated with apple....

    Tank 64 wrote:
    My Daughter changed her Apple ID, not sure why. Then she changed it back to the original. She has lost $50 on her iTunes. How does she restore the funds?
    How did she change her AppleID?
    If she simply updated the AppleID (not created a new one with a new email address), log out then log back into iTunes store.

  • I received a message about having too many contacts?  Not sure what this means, didn't know there limitations on contacts.  Can you tell me about fixing this problem?

    I received a message about having too many contacts?  Not sure what this means, didn't know there limitations on contacts.  Can you tell me about fixing this problem?

    What were you doing when you received the message?
    I have seen reports on these forums where there is a limit to how many contacts you can have in the "to" field of a text message. That is the only thing I can think of where someone has reported getting a warning about too many contacts.

Maybe you are looking for

  • G31TM-P21 One of the usb devices attached to this computer has malfunctioned and

    Just bought the G31TM-P21 motherboard and installed it with a E3200 proc. Whenever I plug in a USB device in one of the four ports on the back panel I get the message: "One of the usb devices attached to this computer has malfunctioned and windows do

  • Problème carte 34901A sur Agilent 34970A

    Bonjour, J'ai un problème sur l'acquisition en impédance de mes cartes 34901A des centrales d'acquisition Agilent 34970A. Lorsque j'utilise mon programme labview, la centrale me retourne une valeur d'impédance fausse. (pour une résistance connue 351O

  • Cannot install driver for Satellite L40

    I have one little problem! I install all drivers but 1 device is not found. I dont know what is this. Help me, people, please!

  • Best Shopping Cart?

    For ASP Classic, what is the best shopping cart? We will probably just go through PayPal, but would like options for normal certificates like Verisign. Any suggestions? I have been looking at WebAssist's software. Any pros or cons there? Thank you al

  • On idle-handler problem

    i want to create an stay-open-applescript-application with "on idle"-handler. to prevent accidental quitting of the script, i'm additional using the "on quit"-handler. but if the quit-handler will not be continued, the idle-handler doesn't continue h