One tuff parsing question?

I read in three lines of data.
This is what the data looks like:
Joe|22|math|A
Ladan|21|english|C
Kyle|22|accounting|F
Can someone please show me code that will return a string that looks like this...
return String Results = "math|english|accounting";

Try this:
BufferedReader br=new BufferedReader(new InputStreamReader(inputStream));
String nextLine="";
String retStr="";
StringBuffer sBuf=new StringBuffer();
char pChar='|';
int pLoc=2;
while((nextLine=br.readLine())!=null) {
try {
retStr=doStuff(nextLine, pLoc, pChar);
catch(Exception ex) {
System.out.println("Error parsing a line");
continue;
sBuf.append(retStr);
sBuf.append(pChar);
String lastStr=sBuf.toString();
lastStr.substring(0, lastStr.length()-1);
public String doStuff(String thLine, int pLoc, char pChar)
throws Exception {
//pLoc is the index of the token to find
//pChar is the delimiter character
int lLen=thLine.length();
int stInd=0;
int fiInd=-1;
for(int count=0;;count++) {
stInd=thLine.indexOf(pChar, stInd);
if(stInd==-1)
throw new Exception();
if(count==pLoc) {
fiInd=thLine.indexOf(pChar, stInd+1);
if(fiInd==-1)
return thLine.substring(stInd+1, thLine.length());
return thLine.substring(stInd+1, fiInd);
stInd+=1;
}

Similar Messages

  • I have an older model of the ipod shuffle, we forgot the itunes log in and pass so we created a new one. My question is how to i get that music that is on the shuffle on the computer?

    I have an older model of the ipod shuffle, we forgot the itunes login and pass so we created a new one. My question is how do we transfer that music that is on the shuffle to the computer? It will not let me do anything... The music titles are all dulled out, the only thing i can do is listen to them but I cannot do anything else.
    Please help thanks!

    maddkeeper wrote:
    I have an older model of the ipod shuffle, we forgot the itunes login and pass so we created a new one. My question is how do we transfer that music that is on the shuffle to the computer?
    You do not.  Content is permanently tied to the Apple ID that it was acquired with.
    Sign out of the computer with the new Apple ID.  STOP using the new Apple ID.
    Sign in with the original Apple ID that the content was acquired with.
    For forgotten Apple IDs/passwords: http://iforgot.apple.com

  • Mavericks, only one site show question mark instead of images

    Hi,
         Updated to Mavericks, only one site show question mark instead of images. Tried safari, chrome and firefox all of them have same problem of showing images of this site. Tried reset, empty cachs, cookies, did not work. Any one have a clue to solve this? Thx.
    BTW, the site is: ssense.com

    Thanks! lol, seems silly now i had to post here when all i had to do was close and relaunch... sorry for wasting your time. thanks to those who answered.

  • One very basic question about inheritance

    One very basic question about inheritance.
    Why we need inheritance?
    the benefit of inheritance also achieve by creating instance of base class using it in other class instead of extending the base class.
    Can any one please explain why we are using inheritance instead of creating object of base class????

    SumitThokal wrote:
    One very basic question about inheritance.
    Why we need inheritance?
    the benefit of inheritance also achieve by creating instance of base class using it in other class instead of extending the base class.
    Can any one please explain why we are using inheritance instead of creating object of base class????What did you find out when you looked on Google?
    One example of inheritance comes in the form of a vehicle. Each vehicle has similarities however they differ in their own retrospect. A car is not a bus, a bus is not a truck, and a truck is not a motorbike. If you can define the similarities between these vehicles then you have a class in which you can extend into either of the previous mentioned vehicles. Resulting in a reusable class, dramatically reduces the size of code, creates a single point of definition, increases maintainability, you name it.
    In short there are thousands of benefits from using inheritance, listing the benefits could take a while. A quick Google search should give you a few hundred k if not million links to read.
    Mel

  • Tough Parsing question???

    Please try to help me with the following parsing question.
         I have an exert from the 2000 Tiger/Line Census files that looks
         something like this:
         0001     A     Libby     Ln     -92.99999+25.87787      -92.87679+26.65543
         0002     A     Capri     Ave     -93.32343+23.3332 3      -24.34444+34.22222
         0003     A     Minster Grove Ln     -93.23433+22.2223432     -98.343343+23.34332
         0003     A     Houston Ave -91.99892+22.323322     -98.434543+33.33233
         0004 A I-10          Int -91.23234+32.343232     -97.333233+34.22222
         0005 C     Trenton Springs Ct. -90.22232+33.222123          -91.234432+23.33221
         I want to parse it so I can enter it into an SQL database.
         Normally this would be an easy task but, the file is not comma
         deliminated. Usaully I could just break it apart at the white space
         but as you can see above, some of the street names (the third column)
         have whitespace in the text. I have almost declared it impossible
         and am about to give up an buy prepackaged/parsable software.
         I will feel very small if I have to do that.
         Thanks for any help,
         Ian

    public class CensusParser
         String[] census = {     "0001     A     Libby                       Ln     -92.99999+25.87787                 -92.87679+26.65543",
                                  "0002     A     Capri                       Ave     -93.32343+23.3332 3                -24.34444+34.22222",
                                  "0003     A     Minster Grove    Ln     -93.23433+22.2223432             -98.343343+23.34332",
                                  "0003     A     Houston               Ave    -91.99892+22.323322           -98.434543+33.33233",
                                  "0004    A       I-10                     Int    -91.23234+32.343232                 -97.333233+34.22222",
                                  "0005   C     Trenton Springs Ct.    -90.22232+33.222123           -91.234432+23.33221" };
         int cur, flds;
         String n = "";
         void parse() {
              for (int x=0; x<census.length; x++) {
                   flds = 0;
                   cur=census[x].length();
                   n = "";
                   for (int y=census[x].length()-1; y>=0 && flds < 4; y--) {
                        if (census[x].charAt(y) == '-' || census[x].charAt(y) == '+') {
                             n = "," + census[x].substring(y, cur).trim() + n;
                             cur = y;
                             flds++;
                   n = census[x].substring(0, cur).trim() + n;
                   census[x] = n;
                   System.out.println(n);
         public static void main(String[] args) {
              CensusParser cp = new CensusParser();
              cp.parse();
    }Not very efficient, but it works!
    Mark

  • HT1911 How do i change/find the answer to one of the questions like; "who is your favorite teacher?"

    How do i change/find the answer to one of the questions like; "who is your favorite teacher?" I need to be able to buy stuff off of my computer.

    Go to:
    https://appleid.apple.com/
    Click "Manage My Account", sign in, and go to the Password and Security section. Answer the security questions and you'll be taken to a screen where you can then change them. If you've forgotten your answers, there should be a link just under the security questions fields where you can have a reset email sent to your Rescue email address. If the link for the email doesn't appear, as can happen if you didn't set a rescue email address or (apparently) have a .Mac email address, go here:
    http://www.apple.com/emea/support/itunes/contact.html
    to report the issue to the iTunes Store.
    Regards.
    Forum Tip: Since you're new here, you've probably not discovered the Search feature available on every Communities page, but next time, it might save you time (and everyone else from having to answer the same question multiple times) if you search a couple of ways for a topic, both in the relevant forums and in the Apple Knowledge Base, before you post a question.

  • Answers the one million dollars question: Forms or Java.

    there was an event held by oracle experts but i did attend the event and one of the point to discuss was
    "Answers the one million dollars question: Forms or Java." as they name it.
    so i want to know what is better to use JSP and JEEP technology or to use Oracle forms and PL/SQL to integrate them to gether.

    but is this sentence true " that Java ,and JSP are
    more web oriented than oracle forms" i am saying here
    about the web application are JSP pages more
    appropriate since they are made specially for
    developing the web environment and that Oracle is
    more appropriate to the client/server environment
    hint"
    You are confusing the language with the architectural implementation of that language. Delphi for example has a very tight web integration architecture - supporting developing Apache and IIS plug-in modules, CGIs.. or even (using Indy Classes) building your own custom web server. You'll find the same type of thing with many other languages. Including Java. Including PL/SQL.
    Java is a language. PL/SQL is a language. Delphi etc.. are all just languages. Anyone that states that one language is "better" than another is, well.. grossly mistaken. (trying hard to put it into polite terms).
    Yes, developers have their favourite languages. Pascal/Delphi is mine. But that means nothing when you select a language and an architecture for doing a specific job, meeting a specific business requirement. You select the best tool for the job. That simple.. and that complex.
    Java and J2EE are not The Single Solution To All Information System Problems. But this is exactly what J2EE (and Java) is sold as by the religious fanatics and prophets of Java... and why there is this mistaken believe that Java is somehow better than other programming language.. and that J2EE is somewhat superior to other architectures.
    And that is simply bull. No matter how prettily pink it is painted, it still smells like the turd it is.

  • HT5312 do not remember an anwer to one of the questions

    do not remember an anwer to one of the questions
    how do i find out the answer?

    Alternatives for Help Resetting Security Questions and Rescue Mail
         1. Apple ID- All about Apple ID security questions.
         2. Rescue email address and how to reset Apple ID security questions
         3. Apple ID- Contacting Apple for help with Apple ID account security.
         4. Fill out and submit this form. Select the topic, Account Security.
         5.  Call Apple Customer Service: Contacting Apple for support in your
              country and ask to speak to Account Security.
    How to Manage your Apple ID: Manage My Apple ID

  • HT201303 using a new computer, and cannot download music without being able to answer security questions.  Is there a way to reset these or get the answers sent to you for one's security questions.

    using a new computer, and cannot download music without being able to answer security questions.  Is there a way to reset these or get the answers sent to you for one's security questions.

    If you have a rescue email address set up on your account then you can try going to https://appleid.apple.com/ and click 'Manage your Apple ID' on the right-hand side of that page and log into your account. Then click on 'Password and Security' on the left-hand side of that page and on the right-hand side you might see an option to send security question reset info to your rescue email address.
    If you don't have a rescue email address set up then go to Express Lane  and select 'iTunes' from the list of 'products' in the middle of the screen.
    Then select 'iTunes Store', and on the next screen select 'Account Management'
    Next choose 'iTunes Store Account Security' and fill in that you'd like your security questions/answers reset.
    You should get an email reply within, I think, about 24 to 48 hours (and check your Spam folder as well as your Inbox)

  • Interesting SAX Parser Question

    I am running a BEA Sample weblogic server and trying to parse in XML using SAX.The endElement in the sample program to parse the XML takes only one parameter like follows
    public void endElement(String name) throws SAXException {
    its not taking the local name.. in that case what should i do .. i won;t get the local name
    I tried to change it to as follows
    public void endElement(String namespaceURI, String localName,
    String name)throws SAXException
    and printing the localName.. its always empty.
    The sample code extends like this..
    public class RequestHandler extends DefaultHandler {
    Will it make any difference ? If i extend from ContentHandler will it solve the problem ? .. Please help me
    Thanks,
    -Raj..

    Thanks sir and figured that out earlier itself..
    My question now is why i am not getting the "localName" in startElement & endElement function when i extend my class using DefaultHandler ?
    I know if the Namespace is false or not present i won't get the localName.
    But my XML has namespace .. and i get the "localName" when i extend the class using ContentHandler .. at the same time when i extend my class using DefaultHandler i am not getting the "localName" .. Do i need to explicity perform the Namespace processing ??
    I am confused why i am getting localName when i extend from ContentHandler & not when i extend it from DefaultHandler ?
    class MyHandler extends DefaultHandler {
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    // localName is always empty here
    public void endElement(String uri, String localName, String qName) throws SAXException {
    // localName is always empty here
    class MyHandler extends ContentHandler {
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    //localName has Expected Value
    public void endElement(String uri, String localName, String qName) throws SAXException {
    //localName has Expected Value
    This is the XML i have :
    <?xml version="1.0" encoding="UTF-8"?>
    <SubscriberNotification xmlns:cng="http://cs.com/CSI/Namespaces/Types/Public/DataModel.xsd"
    xmlns="http://cs.com/Namespces/Container/JMS/SubscriberNotification.xsd"
    xmlns:sn="http://cs.com/Namespaces/Container/Public/SubscriberNotification.xsd"
    xmlns:mh="http://cs.com/Namespaces/Container/Public/MessageHeader.xsd">
    <mh:TrackingMessageHeader>
    <cng:version>v3</cng:version>
    </mh:TrackingMessageHeader>
    <sn:SubscriberNotification>
    <sn:DateTime>2003-12-10T11:17:27.377Z</sn:DateTime>
    <sn:Subscriber>
    <sn:subscriberNumber>1234567890</sn:subscriberNumber>
    </sn:Subscriber>
    </sn:SubscriberNotification>
    </SubscriberNotification>

  • Multiple devices (iPads & iPods) on one Apple ID - questions

    OK, here are my questions.  Any help/advice would be appreciated as I'm only a recent Apple convert (after 30 years of refusing to buy Apple!):
    a)  Can I manage my entire family's devices (4; 2 iPads + 2 iPod Touch's) with a single Apple ID (which also happens to be my email address)?
    b)  If I do this, do I just need to pay for any app once, and the whole family can use it on their respective devices simultaneously?  (I come from the Microsoft/PC world where it's always 1 user at a time per license - such as MSOffice)
    c)  Can we play multiplayer games via wi-fi, bluetooth, or gamecenter/OpenFeint, etc. using our 'single purchased' app on each device?  I'm talking about games like Dungeons 2 HD, Words with Friends, etc.  Note that each device may have a different version (HD, universal, iPhone/iPod only, iPad only, etc.).
    d)  What about more expensive business type apps like Documents to Go or even the IOS version of MS Office 2010?  Can these be shared and used by all devices with just one purchase?
    e)  What happens to apps like Messaging, FaceTime, or iCloud?  If the 4 devices are all signed on under 1 Apple ID, can we each communicate separately...and simultaneously?  If someone messages my daughter, I don't want to get the message on my iPad, etc.  How do we retain our Messaging-specific identity?  FaceTime?  iCloud space?
    f)  If I re-register one of the devices (my wife's) that's currently on her own Apple ID over to my Apple ID, what happens to her previously purchased apps (under her current Apple ID)?
    g)  Are in-app purchases also "shared" by every device linked to a single Apple ID?
    h) When I synch each device to iTunes after they're linked to a single Apple ID, will the synch try to install every app that we 'collectively' purchase...instead of just the ones we each want on our device?  Will the synch also attempt to download every song and video which may be on the iTunes account?
    LOTS of questions, but I'm still a newbie to the wonderful Apple ecosystem.  Although I was totally skeptical at first, if in fact multiple users within a household can use an app purchased just once, this is a HUGE plus over the whole PC/Microsoft and even Android ecosystem!!  But before I flip the switch and move the other devices over to a single Apple ID (mine), I'd like to hear from some of you who have some definitive answers.  Any DISadvantages to running all 4 devices from a single Apple ID?  I'm also a bit confused as to the linkage between an Apple ID and an email address, as well as the hierarchy/relationship between an Apple ID and an iTunes account.
    Thanks in advance!

    Answers that I know :
    a, yes - I have an iPad, iPhone, and iPod Touch linked to my account on the same computer/iTunes and haven't had any problems with it
    b, you only need to purchase the app once, it can then be copied onto all your devices. Some of my apps are on all three of my devices. If you get newspapers or magazines then I believe that some only allow one download of each magazine/newspaper, so you may not be able to have them on each device.
    c, as long as you have your own Game Center accounts then you should be able to - I've never used it
    d, yes, you can have them on all your devices, you don't need to multi-purchase them
    e, I think that you will each need your own email address for them - in Settings > iMessage you can link an email address with messaging, and similarly for FaceTime (Settings > FaceTime) - that way messages/calls will only go to the correct person. Using FaceTime ; there is also some info on the built-in apps in iPad's manual and iPod's manual
    f, all content purchased via an iTunes account is tied to that account, and they cannot be copied or transferred to a different account. So any content purchased on your wife's account will remain tied to her account. You can have more than one iTunes account authorised on a computer's iTunes (Store > Authorise This Computer), so you can have her content as well as yours on the computer that you sync to.
    g, don't know, I've not made any in-app purchase
    h, with the device connected to and selected on the left-hand side of your computer's iTunes, then on the tabs on the right-hand side you can control what is synced to that device. Those selections should then be remembered each time you re-connect that device, so you can have different selections for each device and you shouldn't have to re-do the selection each time you connect it.

  • HP Officejet 6310 all-in-one wireless option questions

    I have a HP Officejet 6300 All-in-One printer and I was using it with my wire network connection. I just moved to a new home, which I rent, and I do not want to make new wholes to past the cables then this is my question:
    "I have a Cisco Linksys AE1000 high performance wireless-N usb adpater (dual band)" and I saw this product Female USB A to Male Ethernet RJ45 Plug Adapter (on Amazon that I think will be great if I can use it). Can I connect them to make my printer wireless?"
    Please help.
    Thanks.
    BAK

    Unfortunately that will not work for this printer. Wireless printing is set up through the printers software that you install on your computer. Since this printer is not a wireless printer, there will be no option to set it up wirelessly in the software, the only options will be ethernet or USB. 
    -------------How do I give Kudos? | How do I mark a post as Solved? --------------------------------------------------------

  • XML - SAX Parsing Question

    Hi,
    I am parsing XML using SAX parser and fill the values into the HashTable ( like Key value pair ).. so i can get the vaues for a particular key using hash get function.
    For the following XML. There are 2 "subscriberNumber" attribute, one is under "sn:Subscriber" and the another is under "sn:SubscriberChange".
    I can able to put this values in hash table and when i print the Hash table it is printing as sn:subscriberNumber=[1234567890, 1234567890] .. But how will i know which one is from "sn:Subscriber" and which is from "sn:SubscriberChange"
    This is the XML :
    <sn:SubscriberNotification>
    <sn:notificationSubType>1120</sn:notificationSubType>
    <sn:Subscriber>
         <cng:PaymentType>PostPaid</cng:PaymentType>
         <sn:subscriberNumber>1234567890</sn:subscriberNumber>
    </sn:Subscriber>
    <sn:SubscriberChange>
         <sn:subscriberNumber>1234567890</sn:subscriberNumber>
    </sn:SubscriberChange>
    </sn:SubscriberNotification>
    Any suggestion and pointers are really helpful
    Thanks,
    -Raj..

    Try something like this:
    import java.util.Stack;
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
    class MyHandler extends DefaultHandler {
        Stack openTags = new Stack();
        public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
            if (qName.equals("sn:subscriberNumber")) {
                String parentTag = (String)openTags.peek();
                System.out.println("Parent tag of this <sn:subscriberNumber> is : <" + parentTag + ">");
            openTags.push(qName);
        public void endElement(String uri, String localName, String qName) throws SAXException {
            openTags.pop();
    }Regards

  • Any bright ideas? (string parsing question)

    Hi,
    I need to put together some static methods for parsing and comparing strings in different formats. I've written the skeleton methods with some nice comments below:
    public class ParsingTools {
        * This method should be able to convert a string that contains
        * a date in an arbitrary format, to a java.util.date.
        * E.G. '10.12.1998 4:15 AM', 'Jan 6th 1984', '1/01/00'
        * '24th Feb 1975 0530hrs'.  The boolean 'usa' parameter indicates
        * whether its usa style dates: mm/dd/yyyy, instead of dd/mm/yyyy.
        * @param inputDate
        * @param usa
        * @return
       public static Date parseStringDate(String inputDate, boolean usa){
          Date outputDate = null;
          return outputDate;
        * This method should be able to convert strings like:
        * "$10,000.45" to the double 10000.45, or even:
        * "'x=$$254,433,344.003'" to 254433344.00.  All kinds of
        * extraneous characters could be received, this method extracts
        * and returns the number part.
        * @param inputString
        * @return
       public static double parseMoneyString(String inputString){
          double outputDouble = 0.0;
          return outputDouble;
        * This method takes two strings, the first of which is compared
        * to the second to see if they are a close enough match.
        * E.G. " exerci$ed_" compared with "EXERCISED" should return
        * true, but "elephant" compared with "EXERCISED" should return
        * false.
        * @param inputString
        * @param compareString
        * @return
       public static boolean matchToString(String inputString,
                                           String compareString){
          boolean matches = false;
          return matches;
    }Ok, the getting the double from the money string one is easy, just search through the string until you find some numbers, and strip out any commas.
    If anyone has any ideas on a clever way of doing the date parsing, and the string compare one, or knows of existing methods to do these, I'd love to hear about it.
    Many long hours of messing around with string operations await me otherwise!
    Thanks

    I need to put together some static methods for
    parsing and comparing strings in different formats.
    I've written the skeleton methods with some nice
    e comments below:Why isn't java.text.DateFormat good enough for you? I'll bet they do it better.
    I'd use Locale for currencies.
    This is a case where stuff that's already available to you should be preferred. Why write your own when someone else has already done it better? You don't have to maintain it, either. JMO, of course.
    >
    public class ParsingTools {
    * This method should be able to convert a string
    ring that contains
    * a date in an arbitrary format, to a
    to a java.util.date.
    * E.G. '10.12.1998 4:15 AM', 'Jan 6th 1984',
    84', '1/01/00'
    * '24th Feb 1975 0530hrs'.  The boolean 'usa'
    usa' parameter indicates
    * whether its usa style dates: mm/dd/yyyy,
    yyy, instead of dd/mm/yyyy.
    * @param inputDate
    * @param usa
    * @return
    public static Date parseStringDate(String
    ing inputDate, boolean usa){
    Date outputDate = null;
    return outputDate;
    * This method should be able to convert strings
    ings like:
    * "$10,000.45" to the double 10000.45, or even:
    * "'x=$$254,433,344.003'" to 254433344.00.  All
    All kinds of
    * extraneous characters could be received, this
    this method extracts
    * and returns the number part.
    * @param inputString
    * @return
    public static double parseMoneyString(String
    ing inputString){
    double outputDouble = 0.0;
    return outputDouble;
    * This method takes two strings, the first of
    t of which is compared
    * to the second to see if they are a close enough
    ough match.
    * E.G. " exerci$ed_" compared with "EXERCISED"
    SED" should return
    * true, but "elephant" compared with "EXERCISED"
    SED" should return
    * false.
    * @param inputString
    * @param compareString
    * @return
    public static boolean matchToString(String
    ing inputString,
    String
    String
    String compareString){
    boolean matches = false;
    return matches;
    }Ok, the getting the double from the money string one
    is easy, just search through the string until you
    find some numbers, and strip out any commas.
    If anyone has any ideas on a clever way of doing the
    date parsing, and the string compare one, or knows of
    existing methods to do these, I'd love to hear about
    it.
    Many long hours of messing around with string
    operations await me otherwise!
    Thanks

  • String parser question based on oracle grammer

    If i have a string like :
    update employee
    set wtKey = name||pno||id
    where id is not null
    Then my API should return this when i pass "||"
    name||pno||id
    I tried doing it using ' ' as dilimiter and check to see if the parsed string has || but that won't work when the above update cmd is written in the following manner:
    update employee
    set wtKey = name || pno || id
    where id is not null
    (or)
    update employee
    set wtKey = name|| ' ' ||id
    where id is not null
    Is there any API or third party stuff that can perform such operation instead of we parsing it based on some assumptions.
    Any help would be appreciated

    Matt,
    In simple terms, whenever you change some thing, its needed to be logged for the recovery. So when we change Oracle's datablock's data, we are creating one entry. The change has an undo entry also related to it, this would go to the Undo block. Now 'go' means we are updating undo block's current image(whatever it may be) with our current undo image for our transaction, a change hence has to be logged, second redo entry. Transaction table again has to be updated to maintain the entries of the current transaction, some records over there are updated, hence redo.
    The basic thing is that Oracle would make sure that we have all the changes, where ever they are done, logged in the log files for the crash. In case we wont have it, we wouldn't be able to perform recovery.
    A very simplified explanation :-).
    Aman....

Maybe you are looking for