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.

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

  • [C] Trying to sort string into reverse order ... Blank. [SOLVED]

    Here are the pre-processors:
    #include <stdio.h>
    #include <string.h>
    Here are the global variables:
    char output[999];
    Here's the function to sort string to reverse order (I THINK THE PROBLEM IS HERE):
    char output[999];
    char *sort_reverse(const char *str)
    int i, j = 0;
    for (i = strlen(str); i > 0; i--)
    output[j] = str[i];
    j++;
    return output;
    And, function int main(void):
    int main(void)
    printf("Reverse of \"Hello\": %s\n", sort_reverse("Hello"));
    return 0;
    The output is:
    Reverse of "Hello":
    Why is that? how can i fix that?
    Last edited by milo64 (2013-03-28 01:45:46)

    Instead of the global char output[999] wich is really big, you could allocate a perfectly sized array with calloc - like this in the sort_reverse function:
    char *output = calloc(strlen(input_string), sizeof(char));
    and in main program:
    char *reversed_string = sort_reverse("Whatever");
    printf("%s\n", reversed_string);
    //Remember to free reversed_string with
    free(reversed_string);
    //Since its allocated in the heap with calloc()
    Try check man-page for calloc, it will zero out the bytes aswell, then you wont have to worry about setting the last element to '\0'.
    NOTE: you have to iterate with "strlen(input_string) - 1" otherwise you will overwrite the needed '\0'
    EDIT:  As strlen excludes the '\0' in original string, then you have to make space for that by adding one to strlen return value so:
    char *output = calloc(strlen(input_string) + 1, sizeof(char));
    Last edited by Boogie (2013-04-05 09:46:12)

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to get string in reverse order?

    Hi I have line as follows...
    String line = "officer.Bangalore, ind",corp\user,passwordAdapter;I want to get the out put of string in reverse order....
    passwordAdapter,corp\user, "officer.Bangalore, ind" please help on code to get this output....
    I tried with using StringBuffer class but it reversing the content of string but not order of string..
    thank in advance....
    Jags

    srry for that...
    lets assume the above is line from file and storing in a string variable..
    In that case.. how can i reverse the order of string(line)...
    i know it should be like this..
    String line = "\"officer.Bangalore, ind\",corp\user,passwordAdapter";plz do the needfull...
    thanks,
    jags

  • 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

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

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

Maybe you are looking for

  • Can anyone help me with getting the best setting for me system

    can anyone help me with getting the best setting for me system on cpufan it says my temp is 38c but on corecentre it says 42c can anyone help get my system overclocked any more but keeping it stable as well thanx in advance for the help  

  • Text Copied from Illustrator CC 2014.1.0 Pastes as Image

    I have seen similar discussions but none of the answers are of any help to me as of today. Background: I am running OS X Yosemite 10.10 All my CC apps are up to date as of (11/1/14) I am also up to date on all other software on my Mac My goal: Copy t

  • Stuck in infinite loop of dialog boxes

    I dragged a directory into Final Cut Pro 6.0.2 and this is the chain of dialog boxes: "Please choose a translation document file." <OK> "Choose a File" <Cancel> (I can't hit <Choose> because I don't have a translation document file) "ERROR: No transl

  • 96k playback problem

    I am experiencing issues with 24/96 playback in iTunes with my Tascam FW1884 firewire interface and I was hoping somebody could shed some light. I am using iTunes 12 on Windows 7 64. I am trying to play an apple lossless file which is 24bit 96k. I ha

  • Installation of SAP BO 4.0

    Hi guys, I have to install SAP 4.0 in my client server on top of MES Camstar Intelligence. The client has give me two keys: 1- SAP BusinessObjects Enterprise for Query, Reporting and Analysis for NUL-5 2- SAP BusinessObjects Enterprise for Query, Rep