String parsing

Hi guys,
Suppose, I have the following line that is read from a file:
"test" "aksks" 1 "ru"
How can I parse the above line into the following format:
String tmp = "test";
String tmp1 = "aksks";
Int id = 1;
String tmp3 = "ru";
Each word is separated by a single space.
Thank you!
Leon

Use StringTokenizer
String line = "test aksks 1 ru";
StringTokenizer st = new StringTokenizer(line, " ");
String tmp = st.nextToken();
String tmp1 = st.nextToken();
int id = Integer.parseInt(st.nextToken());
String tmp3 = st.nextToken();
Hope that helped...

Similar Messages

  • Oracle date string parser

    I really want that oracle can change their command parser engine to be smart enough especially for date string parsing.
    currently the engine will throw error when we type a date string as (for example) '10/10/10', while this command can be accepted in MS-SQLServer.

    AMaster wrote:
    i have stored three numbers in three different variables and want to join all of them to concatanate:
    http://docs.oracle.com/cd/B19306_01/server.102/b14200/operators003.htm
    make a date string , kindly help me with this.
    Edited by: AMaster on Sep 6, 2012 4:12 AMto_date:
    http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions183.htm
    How to ask a question:
    SQL and PL/SQL FAQ

  • MS IE toStaticHTML String Parsing Cross-Site Scripting Vulnerability alarms

    Hi,
    I was wondering if someone else has noted an increase in false positives concerning the following 2 events:
    - Microsoft Internet Explorer toStaticHTML String Parsing Cross-Site Scripting  Vulnerability
    - Microsoft Office Excel Ghost Record Parsing Arbitrary Code Execution Vulnerability
    Obvisouly I see these events because the signature has been introduced recently!!!
    But I wonder if these alarms I'm getting are genuine (and I have a big problem), or if the signature needs to be 'tuned' by Cisco to be a bit less sensitive?
    Anyone has experienced something similar or can shed a light?
    Thanks,
    seb.

    Hello Seb,
    Since I don't have the entire transmission, I can't tell what exactly is commented out in regard to the tags, but the data appears to look something like below.
    e){  
      //v3.0..   
      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
      if (restore) selObj.selectedIndex=0;
    //-->
    @td  
    img{display: block;}
    @import url("p7tp/p7tp_01.css
    With 30419 being related to CVE-2010-3324, I assume the signature is firing due to some match variation of the fact that @import and the tags are showing up in a response from your web server. The toStaticHTML method should remove tags, but the vulnerability is causing that mechanism to fail.
    The oBot User-Agent caught my eye. Google returns several pages to the effect of oBot being a:
    "German spider from Cobion, now part of Internet Security Systems. Scans the web for their clients looking for copyright infringement."
    I'm not sure what benefit this search bot would receive from injecting Javascript into the response.
    I'll forward the capture data to our sig team to confirm whether this should be a legitimate match.
    Thank you,
    Blayne Dreier
    Cisco TAC Escalation Team
    **Please check out our Podcasts**
    TAC Security Show: http://www.cisco.com/go/tacsecuritypodcast
    TAC IPS Media Series: https://supportforums.cisco.com/community/netpro/security/intrusion-prevention?view=tags&tags=tac_ips_media_series

  • Help With String parsing

    Hey guys,
    I need some help with String Parsing. i hope experts here will help me.
    i'm reading a text file and getting data as String in this format
    *ABR, PAT MSSA        2009       7001    B   ABC       Y
    *VBR, SAT ZSSA        2008       5001    A   CED       N
    *ABC, AAT CSSA        5008       001     A   AZX       N
    *CBC, CAT FSSA        308        5001    A   XCV       N
    Now from following lines i have to extract Number data i.e. 2009 and 7001 from 1st line. 2008 and 5001 from 2nd line and so on.
    Can anyone pls suggest me any way to get the data that i want from these Strings
    Thanks for your time to read this.
    Regards,
    sam

    Thanks for the reply
    Data length can vary. ABR, PAT is the last name, First Name of the Users.
    it can be following or any other combination. i just need 2 set of numbers from the complete line rest i can ignore. Any other way to get that
    *ABRaaassd, PATfffff MSSA 2009 7001 B ABC Y
    *VBRaa, SATaa ZSSA 2008 5001 A CED N
    *ABC, AAT CSSA 5008 001 A AZX N
    *CBC, CAT FSSA 308 5001 A XCV N                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Sax String Parsing

    Hi. I want to parse a String that has an xml format with Sax according to a specific scema using xerces. I've written the following code:
    public void parse(String rr) throws Exception {
    SAXReader reader = new SAXReader();
    reader.setValidation(true);
    // specify the schema to use
    try{
    reader.setProperty(
    "C:\\Documents and Settings\\Don Jiovanni\\jbproject\\project",
    "myxsd.xsd"); //this is my xsd
    }catch(Exception e){ System.out.println("Cause: "+e.getMessage()); }
    // add an error handler which turns any errors into XML
    XMLErrorHandler errorHandler = new XMLErrorHandler();
    reader.setErrorHandler( errorHandler );
    try{
    reader.read(rr); //pase the string
    }catch(Exception ex){System.out.println("Cause: "+ex.getMessage());}
    //output the errors as XML
    XMLWriter writer = new XMLWriter( OutputFormat.createPrettyPrint() );
    writer.write( errorHandler.getErrors() );
    What i get is 2 exceptions:
    for the first try...catch:
    "Property: C:\Documents and Settings\Don Jiovanni\jbproject\project"
    and for the second one:
    "The filename, directory name, or volume label syntax is incorrect"
    Any help...?

    loadGame( new StringReader( someBuffer ) );
    public void loadGame(Reader reader)
         throws ParserConfigurationException, SAXException, IOException, NullPointerException  {
              SAXParserFactory factory = SAXParserFactory.newInstance();
              SAXParser saxParser = factory.newSAXParser();
              saxParser.parse( new InputSource(reader), defaultLoadHandler );
    }

  • XML string parsing

    Is there any class method to parse an XML string into tags and contents?
    I have a response in XML and would like to read a tags contents.
    Thanks

    Hi KP,
    look at the iXML library. http://help.sap.com/saphelp_nw04/helpdata/en/47/b5413acdb62f70e10000000a114084/frameset.htm
    Depending what release you are developing on you might also want to look at SImple Transformations.
    Cheers
    Graham

  • 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 parsing for ip addresses

    Hello,
    Could someone suggest a way or give me some example code to parse the following string?:
    I will have a string something like:
    Internet Address Src: 1.2.3.4 and Dst: 5.6.7.8
    I need to parse this string to store the source IP address 1.2.3.4 in a string call sourceIP and the destination IP address 5.6.7.8 in a string called destinationIP.
    Any suggestions appreciated.
    Many thanks.

    Hello,
    Many thanks for the reply. I have taken on board your advice and now have the following code:
      if ((trimmedstring.startsWith("Internet Protocol, Src Addr:"))){
                System.out.println("<br>" + trimmedstring);
                  //indexof, substring
                int firstmarker = trimmedstring.indexOf("Src Addr:");
                System.out.println("MARKER1" + firstmarker);
                firstIPAddress = trimmedstring.substring(firstmarker, trimmedstring.indexOf("("));
                String newFirstIPAddress = firstIPAddress.replaceAll("Src Addr:", "");
                System.out.println("NBNB First IP Address" + newFirstIPAddress);
                int secondmarker = trimmedstring.indexOf("Dst Addr: ");
                System.out.println("MARKER2" + secondmarker);
                secondIPAddress = trimmedstring.substring(secondmarker, trimmedstring.indexOf("("));
                String newSecondIPAddress = secondIPAddress.replaceAll("Dst Addr: ", "");
                System.out.println("<br>NBNB Second IP Address" + newSecondIPAddress);
              }However I am getting an error when I try to parse out the second IP address i.e. the destination IP address.
    I get the error:
    StringIndexOutOfBoundsException: String index out of range: -17
    The line that I'm working on is:
    Internet Protocol, Src Addr: 157.190.70.67 (157.190.70.67), Dst Addr: 157.190.74.153 (157.190.74.153)
    I don't see where my code should be changed as I think the indexes look correct.
    Any ideas?
    Many thanks

  • String parsing (reversing)

    Hello friedns,
    I have string of the form :
    String s1 = "alex box (hello (how (are))) (sachin how are you) d  you"I want to reverse this string as follows :
    String reversed = "you d (sachin how are you) (hello (how (are))) box alex"Note : In the above translation if there is something inside parenthesis then,
    I want to use it as a single word and I will not reverse the content inside it.
    Would somebody can tell me how can I make such type of translation ?
    Thank you.
    regards,
    sachin

    sachin.annadate wrote:
    Hello friedns,
    I have string of the form :
    String s1 = "alex box (hello (how (are))) (sachin how are you) d  you"I want to reverse this string as follows :
    String reversed = "you d (sachin how are you) (hello (how (are))) box alex"Note : In the above translation if there is something inside parenthesis then,
    I want to use it as a single word and I will not reverse the content inside it.
    Would somebody can tell me how can I make such type of translation ?
    Thank you.
    regards,
    sachinThis looks a lot like your previous post:
    [http://forum.java.sun.com/thread.jspa?threadID=5301673]
    I suggested looking at ANTLR. I will do so again: create a grammar of your language and then let ANTLR do the "dirty" work by generating a lexer and parser for you.

  • String parsing of type @" 2 x (4     -1 ) = "

    I am attempting to parse a string of
    NSString *multiplyString = @" 2 x (4 -1 ) = "
    The problem that I am having is that I cannot separate 4( , or the -1. Hence, any characters that are touching each other. I used NSScanner to remove the blank spaces and store the resulting string values in a NSMutableArray.
    BOOL fBlankSpaces = NO;
    NSString *multiplyString = @" 2 x (4 -1 ) = "
    NSString *gotItTrimmed = [[NSString alloc]init];
    NSScanner *theScanner = [NSScanner scannerWithString:trimmedString];
    NSMutableArray *sTrimmedValues = [NSMutableArray arrayWithCapacity:5];
    while ([theScanner isAtEnd] == NO) {
    fBlankSpaces = [theScanner scanUpToCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:&gotItTrimmed];
    if(fBlankSpaces == YES)
    [sTrimmedValues addObject: gotItTrimmed];
    Thanks for you help and suggestions!

    T2TU wrote:
    Thank you for your suggestions, but how do I convert it to "prefix notation" or "postfix notation"?
    This is a classic programming problem everyone does (or should) in school. There are different ways to do it. This site has some good information. You should be able to find a few dozen other sites with similar instructions.
    Why can't I store each character into an array, after the string is parsed, and then do a mathematical calculation on converted items?
    Because you have to worry about parentheses, precedence, and associativity if you want to do it correctly. Plus, it is an excellent way to learn about trees and stacks.

  • How to use certain parts of a string-parsing???

    I have a form which pulls some data from a db. For example, it pulls the following about what office I work in:
    DS/ISC/GCS/ABC/DEFG
    The DS refers to the larger office, ISC referes to the next office down, and so forth. I CANNOT CHANGE THESE VALUES.
    What I'd like to do is 'disect' this long string based on where the "/" lie in the string.
    I'm basically only interested in the first two offices. In this example DS and ISC. So, when I want to display the parent office, the only string to display is DS and not DS/. Then on another line, I want to display the sub office ISC and not ISC/ . I guess I could parse? But I'm not sure exactly how to do this. If there is another 'easy' way to do this, I'd open to any suggestions.
    TIA

    http://forum.java.sun.com/thread.jspa?threadID=682574&tstart=0

  • String Parsing using Oracle

    Hello,
    I am newbe in Oracle SQL.I need help in parsing Strings.
    Example:
    ID Name Address num
    1 Peter 123 park st,223 park st 123,223
    Answer
    ID Name Address num
    1 Peter 123 park st 123
    1 Peter 223 Park St 223
    Please Help me.
    Thanks.

    Hi,
    If you're using Oracle 10.1 or higher, regular exprssions can help a lot.
    Whatever version of Oracle you're using, this will probably be easier in PL/SQL. You can write a Pipelined Function that takes a string such as '1 Peter 123 park st,223 park st 123,223' as input, and returns a variable number of rows (depending on what is in the input string), like this:
    ID     Name     Address          num
    1      Peter      123 park st      123
    1     Peter     223 Park St     223You probably want some other functions, too, such as a tokenizer, which divides a delimited sting into parts.
    As in any programming task, start by specifying exactly what you want to do. For example
    "An input string s consists of +words+ , that is, sub-strings that do not contain spaces, tabs or commas.
    S can contain 0 or more addresses.
    The first word of s (that is, the sub-string before the first space or tab) is the id. All addresses from the same string will have the same id.
    The second word of s is the name. All addresses from the same string will have the same name. If there is no 2nd word ...
    After the name, s is divided into addresses by commas.
    The first word of each section is the num. This same sub-string is therefore found in 2 columns of the output: address and num.
    If the address consists only of 1 word, then it is ignored."
    Depending on what your requirements are, this problem can be very complicated. Be prepared.
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data. Explain, using specific examples, how you get those results from that data.
    In the sample data and results, include special cases and problems that you might encounter. For example,
    some streets have numbers for names, so you might see '123 45 st' as an address. What if your sting is '1 Peter 45 st'. Is num=45? Can the name be more that 1 word, e.g. '2 Mary Ann 17 Main St'?
    Always say which version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    Edited by: Frank Kulash on Sep 17, 2012 2:50 PM

  • Date String Parsing.

    Hi all,
    I need to parse a date that is input by the user.
    I thought to pick the input string and use it to create a Date object by parsing it.
    example: here inputString is the String that holds the date.
    DateFormat fd = new SimpleDateFormat("dd/MM/yyyy");
                try{
                    Date when = fd.parse(inputString);          
                catch (ParseException pe){
                     <do something to alert the user>
                 }the problem is:
    if I input the following string:
    50/13/2004
    it PARSES GOOD (!!) and the parsed date is
    19/02/2005
    probably because 13/2004 -> 01/2005 and 50 -> 31 + 19...
    any help? Thank you!

    You'll need to setLenient to false before you call parse(), of course...

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

  • Doubt in String Parsing

    Hi,
    "23:BE|2009:A@Banglore"
    i need to parse the above string and retrieve the data's.
    Now i am using the StringTokenizer and my code is this,
    String sz = "23:BE|2009+A@Banglore";
              StringTokenizer szTkn = new StringTokenizer(sz, ":");
              System.out.println(" : " + szTkn.nextToken());
              szTkn = new StringTokenizer(szTkn.nextToken(), "|");
              System.out.println(" | " + szTkn.nextToken());
              szTkn = new StringTokenizer(szTkn.nextToken(), "+");
              System.out.println(" + " + szTkn.nextToken());
              szTkn = new StringTokenizer(szTkn.nextToken(), "@");
              System.out.println(" @ " + szTkn.nextToken());
              System.out.println(" " + szTkn.nextToken());is there any good way to do this?

    vijay wrote:
    You can use backreferencing to capture any group in a matching patterns.
    Take a look at this:
    http://download.oracle.com/javase/tutorial/essential/regex/groups.html
    I don't see how 'backreferencing' comes into this since the OP only needs the content of field values between separators without any direct reference to what has been found before.
    Since the original code suggests the fields are always there and always in the same order I think it is easier still just to use split()
    String sz = "23:BE|2009+A@Banglore";
    String[] splitSz = sz.split("[:|+@]");

Maybe you are looking for

  • Process inbound Idocs only one at a time

    Hi all, I'm searching for a solution to the following problem: We are receiving ORDERS-Idocs into our R/3 4.6C-system. These Idocs are processed by our own Z-function module. The function module's coding should assure that e.g. the first idoc of each

  • RAW files not launching

    After a system crash I reinstalled Lightroom 3.6 and subscribed to Creative Cloud. Downloaded and installed without issue Bridge and Photoshop CS6 - 64bit Windows 7 system. Some (NOT ALL) of the RAW files (ORF) that I restored from a backup will not

  • Problem in creating IR through BAPI_INCOMINGINVOICE_create BAPI

    Hi, Some problem in creating IR through the BAPI BAPI_INCOMINGINVOICE_create. I am able to see the IR number after executing the BAPI but unable to see the IR number in the table. The IR number is not getting updated in the database table even though

  • Problem when printing

    Hi guys, I'm having a problem that has been bugging me for quite a while now. Whenever I print something from SAP, I get the background all black! Does anyone know a way around it? I don't know if its something from SAP or the printer, but it has onl

  • IMac as quasi-DVD player

    We are new Mac owners, and I'm hoping I can fetch an answer from you experienced types out there. We have an iMac 20" and an 32" LCD HDTV 720 res. We use Airport Express for our wireless internet connection and printer. My high-class Walmart DVD play