String a== string b question

Hi,
I was told that when compare objects using ==, the reference of the objects are being compared not the data. My question is for the following two strings, why is it (s1==s2) result true. They are two different objects and should have different reference. Therefore, the result should be false. Can anyone advise. Thanks.
String s1 = "abc";
String s2 = "abc";

Actually, the String Object has its own implementation of method equals(), which is different of the default one provided by the Object class.
The String's equals method returns true if the to args has the same characters.
That is, if you have
String one = "abc" ;
String two = "abc" ;
String three = one ;
String four = one + "d" ;
one.equals(three) will return true,
one.equals(two) will return true,
one.equals(four) will return false...

Similar Messages

  • Very simple XSLT string replacing question

    Hi,
    This is a really simple question for you guys, but it took me long, and i still couldn't solve it.
    I just want to remove all spaces from a node inside an XML file.
    XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <root insertedtime="2008-05-01T14:03:00.000+10:00" pkid="23421">
       <books>
          <book type='fiction'>
             <author>John Smith</author>
             <title>Book title</title>
             <year>2 0  0 8</year>
          </book>
       </books>
    </root>in the 'year' node, the value should not contain any spaces, that's the reason why i need to remove spaces using XSLT. Apart from removing space, i also need to make sure that the 'year' node has a non-empty value. Here's the XSLT:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:strip-space elements="*"/>
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="//books/book[@type='fiction']">
            <xsl:copy>
                <xsl:apply-templates select="@*"/>
                <xsl:attribute name="id">101</xsl:attribute>
                <xsl:call-template name="emptyCheck">
                    <xsl:with-param name="val" select="year"/>
                    <xsl:with-param name="type" select="@type"/>
                    <xsl:with-param name="copy" select="'true'"/>
                </xsl:call-template>
                <xsl:value-of select="translate(year, ' ', '')"/>
            </xsl:copy>
        </xsl:template>
        <!-- emptyCheck checks if a string is an empty string -->
        <xsl:template name="emptyCheck">
            <xsl:param name="val"/>
            <xsl:param name="type"/>
            <xsl:param name="copy"/>
            <xsl:if test="boolean($copy)">
                <xsl:apply-templates select="node()"/>
            </xsl:if>
            <xsl:if test="string-length($val) = 0 ">
                <exception description="Type {$type} value cannot be empty"/>
            </xsl:if>
        </xsl:template>
    </xsl:stylesheet>The 'emptyCheck' function works fine, but the space replacing is not working, this is the result after the transform:
    <?xml version="1.0" encoding="utf-8"?>
    <root insertedtime="2008-05-01T14:03:00.000+10:00" pkid="23421">
       <books>
          <book type="fiction" id="101">
             <author>John Smith</author>
             <title>Book title</title>
             <year>2 0 0 8</year>2008</book>
       </books>
    </root>The spaced year value is still there, the no-space year is added outside the 'year' tags'
    anyone can help me, your help is extremely appreciated!
    Thanks!

    You should add a template for 'year' :<xsl:template match="year">
    <year><xsl:value-of select="translate(.,' ','')"/></year>
    </xsl:template>and remove the translate call in the 'book' template.
    It would be better to add a 'priority' attribute at each template so it would be explicit which template to use because match="@*|node()" could be interpreted by another transform engine as the unique template to be used !

  • How do I view previous strings of questions and answers on FF support?

    I read this response but it really doesn't answer the question.
    "If you are logged on then you see a My Contributions item in the Filter bar at the top that goes to:
    https://support.mozilla.org/questions?filter=my-contributions"
    I don't see the "filter bar" or "my responses" after I log in. I just see "Ask a question" "my log in name" and some other stuff to the right of that and below that.
    So after I log in, how do I look at strings of my previous questions and all responses to them, including new ones?

    I just figured it out!!! Wha-lah. Go to a question and then click on the underlined text in the question. Then a string of the Q and subsequent responses appears.

  • Classes and subclasses given as String input - question

    Hello, I am new in Java so please don't laugh at my question!!
    I have a method as the following and I am trying to store objects of the type Turtle in a vector. However the objects can also be of Turtle subclasses: ContinuousTurtle, WrappingTurtle and ReflectingTurtle. The exact class is determined by the String cls which is input by the user.
    My question is, how can I use cls in a form that I don't have to use if-else statements for all 4 cases? (Imagine if I had 30 subclasses).
    I have tried these two and similar methods so far but they return an error and Eclipse is not of much help in this case.
    Simplified methods:
    //pre:  cls matches exactly the name of a valid Turtle class/subclass
    //post: returns vector with a new turtle of type cls added to the end
    private Vector<Turtle> newturtle(Vector<Turtle> storage, String cls){
         Turtle t = new cls(...);
         storage.add(t);
         etc.
    private Vector<Turtle> newturtle(Vector<Turtle> storage, String cls){
         Turtle t = new Turtle<cls>(...);
         storage.add(t);
         etc.
    }Thanks for your help.
    p.s.: I didn't know whether to post this question here or under Generics.

    a Factory is atually very simple (100x simpler than reflection).
    example:
    class TurtleFactory
      public Turtle makeTurtle(String typeOfTurtle)
        if (typeOfTurtle.equals("lazy") { return new LazyTurtle(); }
        else if (typeOfTurtle.equals("fast") { return new FastTurtle(); }
        <etc>
    }While at first this doesn't look any better than your original problem, what we've done is made a class that is responsible for all the types of turtles. This will also benefit in case some turtles need initialization or need something passed to their constructor. You encapsulate all that knowledge in one place so you rcode doesn't become littered with it else ladders.

  • String Substitution Questions

    A few questions on APEX substitution strings:
    1. Is APEX using a particular templating engine (Velocity, etc.) or one that you developed to handle the "#VALUE#" substitutions in APEX? If so which one?
    2. Are all the substitution parameters (#VALUE# strings) defined anywhere?
    3. When in the APEX processing cycle are they replaced?
    4. Is there any way to get the current value of a substitution string in a SQL or PL/SQL command (ie. a function or something in the API)?
    5. Is there a list of all the places in APEX where you can use substitution strings?
    6. Is there way for developers to create new substitution strings and set / get the values so that APEX will use them?
    Thanks for everyones help!
    Dave Venus

    Dave,
    I'll do the best I can ...
    1. Is APEX using a particular templating engine (Velocity, etc.) or one that you developed to handle the "#VALUE#" substitutions in APEX? If so which one?
    No, it's all done with our own PL/SQL.
    2. Are all the substitution parameters (#VALUE# strings) defined anywhere?
    In one place, I don't think so. Most of the #VALUE# strings are defined in the template definition pages in the Builder where it shows which strings are supported in which fields. These patterns are also supported in the report attributes pages and are listed there and in associated help text. There are other substitution patterns, of course, the &VALUE. strings. I don't know if you're asking about those. All of the supported strings in that category should be documented in the User's Guide.
    3. When in the APEX processing cycle are they replaced?
    At the point where they are encountered, for example when the containing HTML or PL/SQL structure is being rendered, parsed, etc. The exception would be the built-in &VALUE. strings like &SESSION. which are set at the beginning of each request.
    4. Is there any way to get the current value of a substitution string in a SQL or PL/SQL command (ie. a function or something in the API)?
    Not for the #VALUE# strings unless there are specific exceptions I can't recall at the moment for which APIs have been provided. For the &VALUE. strings, of course, you can use v() and bind variable notation to access the value of VALUE.
    5. Is there a list of all the places in APEX where you can use substitution strings?
    No.
    6. Is there way for developers to create new substitution strings and set / get the values so that APEX will use them?
    Only for &VALUE. strings for which you can define up to twenty name/value pairs in the Applicaiton Definition (Substitutions) section.
    Scott

  • 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

  • Simple string optimization question

    ABAPpers,
    Here is the problem description:
    In a SELECT query loop, I need to build a string by concatenating all the column values for the current row. Each column is represented as a length-value pair. For example, let's say the current values are:
    Column1 (type string)  : 'abc          '
    Column2 (type integer) : 7792
    Column3 (type string)  : 'def                    '
    The resulting string must be of the form:
    0003abc000477920003def...
    The length is always represented by a four character value, followed by the actual value.
    Note that the input columns may be of mixed types - numeric, string, date-time, etc.
    Given that data is of mixed type and that the length of each string-type value is not known in advance, can someone suggest a good algorithm to build such a result? Or, is there any built-in function that already does something similar?
    Thank you in advance for your help.
    Pradeep

    Hi,
    At the bottom of this message, I have posted a program that I currently wrote. Essentially, as I know the size of each "string" type column, I use a specific function to built the string. For any non-string type column, I assume that the length can never exceed 25 characters. As I fill 255 characters in the output buffer, I have to write the output buffer to screen.
    The reason I have so many functions for each string type is that I wanted to optimize concatenate operation. Had I used just one function with the large buffer, then "concatenate" statement takes additional time to fill the remaining part of the buffer with spaces.
    As my experience in ABAP programming is limited to just a couple of days, I'd appreciate it if someone can suggest me a better way to deal with my problem.
    Thank you in advanced for all your help. Sorry about posting such a large piece of code. I just wanted to show you the complexity that I have created for myself :-(.
    Pradeep
    REPORT ZMYREPORTTEST no standard page heading line-size 255.
    TABLES: GLPCA.
    data: GLPCAGL_SIRID like GLPCA-GL_SIRID.
    data: GLPCARLDNR like GLPCA-RLDNR.
    data: GLPCARRCTY like GLPCA-RRCTY.
    data: GLPCARVERS like GLPCA-RVERS.
    data: GLPCARYEAR like GLPCA-RYEAR.
    data: GLPCAPOPER like GLPCA-POPER.
    data: GLPCARBUKRS like GLPCA-RBUKRS.
    data: GLPCARPRCTR like GLPCA-RPRCTR.
    data: GLPCAKOKRS like GLPCA-KOKRS.
    data: GLPCARACCT like GLPCA-RACCT.
    data: GLPCAKSL like GLPCA-KSL.
    data: GLPCACPUDT like GLPCA-CPUDT.
    data: GLPCACPUTM like GLPCA-CPUTM.
    data: GLPCAUSNAM like GLPCA-USNAM.
    data: GLPCABUDAT like GLPCA-BUDAT.
    data: GLPCAREFDOCNR like GLPCA-REFDOCNR.
    data: GLPCAAWORG like GLPCA-AWORG.
    data: GLPCAKOSTL like GLPCA-KOSTL.
    data: GLPCAMATNR like GLPCA-MATNR.
    data: GLPCALIFNR like GLPCA-LIFNR.
    data: GLPCASGTXT like GLPCA-SGTXT.
    data: GLPCAAUFNR like GLPCA-AUFNR.
    data: data(255).
    data: currentPos type i.
    data: lineLen type i value 255.
    data len(4).
    data startIndex type i.
    data charsToBeWritten type i.
    data remainingRow type i.
    SELECT GL_SIRID
    RLDNR
    RRCTY
    RVERS
    RYEAR
    POPER
    RBUKRS
    RPRCTR
    KOKRS
    RACCT
    KSL
    CPUDT
    CPUTM
    USNAM
    BUDAT
    REFDOCNR
    AWORG
    KOSTL
    MATNR
    LIFNR
    SGTXT
    AUFNR into (GLPCAGL_SIRID,
    GLPCARLDNR,
    GLPCARRCTY,
    GLPCARVERS,
    GLPCARYEAR,
    GLPCAPOPER,
    GLPCARBUKRS,
    GLPCARPRCTR,
    GLPCAKOKRS,
    GLPCARACCT,
    GLPCAKSL,
    GLPCACPUDT,
    GLPCACPUTM,
    GLPCAUSNAM,
    GLPCABUDAT,
    GLPCAREFDOCNR,
    GLPCAAWORG,
    GLPCAKOSTL,
    GLPCAMATNR,
    GLPCALIFNR,
    GLPCASGTXT,
    GLPCAAUFNR) FROM GLPCA
    perform BuildFullColumnString18 using GLPCAGL_SIRID.
    perform BuildFullColumnString2 using GLPCARLDNR.
    perform BuildFullColumnString1 using GLPCARRCTY.
    perform BuildFullColumnString3 using GLPCARVERS.
    perform BuildFullColumnString4 using GLPCARYEAR.
    perform BuildFullColumnString3 using GLPCAPOPER.
    perform BuildFullColumnString4 using GLPCARBUKRS.
    perform BuildFullColumnString10 using GLPCARPRCTR.
    perform BuildFullColumnString4 using GLPCAKOKRS.
    perform BuildFullColumnString10 using GLPCARACCT.
    perform BuildFullColumnNonString using GLPCAKSL.
    perform BuildFullColumnNonString using GLPCACPUDT.
    perform BuildFullColumnNonString using GLPCACPUTM.
    perform BuildFullColumnString12 using GLPCAUSNAM.
    perform BuildFullColumnNonString using GLPCABUDAT.
    perform BuildFullColumnString10 using GLPCAREFDOCNR.
    perform BuildFullColumnString10 using GLPCAAWORG.
    perform BuildFullColumnString10 using GLPCAKOSTL.
    perform BuildFullColumnString18 using GLPCAMATNR.
    perform BuildFullColumnString10 using GLPCALIFNR.
    perform BuildFullColumnString50 using GLPCASGTXT.
    perform BuildFullColumnString12 using GLPCAAUFNR.
    ENDSELECT.
    if currentPos > 0.
      move '' to datacurrentPos.
      write: / data.
    else.
      write: / '+'.
    endif.
    data fullColumn25(29).
    data fullColumn1(5).
    Form BuildFullColumnString1 using value(currentCol). 
      len = STRLEN( currentCol ).
      concatenate len currentCol into fullColumn1.
      data startIndex type i.
      data charsToBeWritten type i.
      charsToBeWritten = STRLEN( fullColumn1 ).
      data remainingRow type i.
      do.
        remainingRow = lineLen - currentPos.
        if remainingRow > charsToBeWritten.
          move fullColumn1+startIndex(charsToBeWritten) to
            data+currentPos(charsToBeWritten).
          currentPos = currentPos + charsToBeWritten.
          exit.
        endif.
        if remainingRow EQ charsToBeWritten.
          move fullColumn1+startIndex(charsToBeWritten) to
            data+currentPos(charsToBeWritten).
          write: / data.
          currentPos = 0.
          exit.
        endif.
        move fullColumn1+startIndex(remainingRow) to
            data+currentPos(remainingRow).
        write: / data.
        startIndex = startIndex + remainingRow.
        charsToBeWritten = charsToBeWritten - remainingRow.
        currentPos = 0.
      enddo.
    EndForm.
    data fullColumn2(6).
    Form BuildFullColumnString2 using value(currentCol). 
      len = STRLEN( currentCol ).
      concatenate len currentCol into fullColumn2.
      data startIndex type i.
      data charsToBeWritten type i.
      charsToBeWritten = STRLEN( fullColumn2 ).
      data remainingRow type i.
      do.
        remainingRow = lineLen - currentPos.
        if remainingRow > charsToBeWritten.
          move fullColumn2+startIndex(charsToBeWritten) to
            data+currentPos(charsToBeWritten).
          currentPos = currentPos + charsToBeWritten.
          exit.
        endif.
        if remainingRow EQ charsToBeWritten.
          move fullColumn2+startIndex(charsToBeWritten) to
            data+currentPos(charsToBeWritten).
          write: / data.
          currentPos = 0.
          exit.
        endif.
        move fullColumn2+startIndex(remainingRow) to
            data+currentPos(remainingRow).
        write: / data.
        startIndex = startIndex + remainingRow.
        charsToBeWritten = charsToBeWritten - remainingRow.
        currentPos = 0.
      enddo.
    EndForm.
    data fullColumn3(7).
    Form BuildFullColumnString3 using value(currentCol). 
    EndForm.
    data fullColumn4(8).
    Form BuildFullColumnString4 using value(currentCol). 
    EndForm.
    data fullColumn50(54).
    Form BuildFullColumnString50 using value(currentCol). 
    EndForm.
    Form BuildFullColumnNonString using value(currentCol). 
      move currentCol to fullColumn25.
      condense fullColumn25.     
      len = STRLEN( fullColumn25 ).
      concatenate len fullColumn25 into fullColumn25.
      data startIndex type i.
      data charsToBeWritten type i.
      charsToBeWritten = STRLEN( fullColumn25 ).
      data remainingRow type i.
      do.
        remainingRow = lineLen - currentPos.
        if remainingRow > charsToBeWritten.
          move fullColumn25+startIndex(charsToBeWritten) to
            data+currentPos(charsToBeWritten).
          currentPos = currentPos + charsToBeWritten.
          exit.
        endif.
        if remainingRow EQ charsToBeWritten.
          move fullColumn25+startIndex(charsToBeWritten) to
            data+currentPos(charsToBeWritten).
          write: / data.
          currentPos = 0.
          exit.
        endif.
        move fullColumn25+startIndex(remainingRow) to
            data+currentPos(remainingRow).
        write: / data.
        startIndex = startIndex + remainingRow.
        charsToBeWritten = charsToBeWritten - remainingRow.
        currentPos = 0.
      enddo.
    EndForm.

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

  • String tokenizer question

    I need to parse strings of the form "token A ops token B" where ops can be <, >, =, != and output "tokenA ops tokenB"....(remove spaces in the tokens).
    I can use all the ops as delimiters (though I cant specify '!='), and get the tokens and remove the spaces in them. Using StringTokenizer, I doubt if I can know the exact delimiter I encountered so that I can rebuild the string quickly. Sure, I can do an indexOf() for each of the ops to find the one used in original string. But I am curious to know if there is any better approach to do this (doesnt have to be string tokenizer approach)?

    If the tokens always consist of "word characters" (letters, digits, and underscores) and the operators always consist of punctuation characters, you can do this:   str = str.replaceAll("\\b\\s+\\b", "");

  • String manipulation question (servlet)

    Hello,
    I have a problem replacing parts of a String with values from a HttpServletRequest.
    I have the following method:
    public String replaceVariables(String s, HttpServletRequest request) {
         Enumeration e = request.getParameterNames();
         Vector v = new Vector();
         while(e.hasMoreElements()) {
              v.add(e.nextElement());
         String paramName;
         ListIterator li = v.listIterator();
         while(li.hasNext()) {
              paramName = (String) li.next();
              if (s.indexOf("#" + paramName + "#") > -1) {
                   s = new String(new StringBuffer(s).replace(s.indexOf("#" + paramName + "#"), s.indexOf("#" + paramName + "#") + (("#" + paramName + "#").length()), request.getParameter(paramName).toString()));
         return s;
    }What I am trying to do here is read in a line of text (String s) along with a the htpp servlet request. Put the names of the request paramaters into Vector v.
    Next I try to check the String s for any part of the String that matches one of the parameter names surrounded by #'s. If there is a match then I replace the #string# with the value associated with it in the http servlet request.
    The trouble is, my code on ly replaces the very first variable then stops, I cannot see why it does not do the rest.
    I hope this makes sense to somebody, becuase it doesn't to me :-)
    Thanks for any advise or help

    Yep. I have just done a basic one for testing. The String I read in is:
    username = #username#, action = #action#, email = #email#
    And the html form information that is sent to the servlet is:
    <input type="hidden" name="action" value="test">
    <input type="hidden" name="username" value="testuser">
    <input type="hidden" name="email" value="testemail">
    ....etc.
    I don't know if it makes a difference, I don;t think it does, but I am reading in a whole file, and passing the file line by line to this method.
    The method that passes each line is:
    public Vector generateHTML(HttpServletRequest request) {
         Vector v = new Vector();
         try {
              File f = new File("/fakepath/" + request.getParameter("action") + ".template");
              FileReader fr = new FileReader(f);
              BufferedReader br = new BufferedReader(fr);
              String s;
              while((s = br.readLine()) != null) {
                   s = replaceVariables(s, request);
                   v.add(s);
         } catch (Exception e) {
              // ignore
         } finally {
              return v;
    }

  • String Tokenizing Question

    Hello -
    I'm able to tokenize w/o any problems, save for when I run into consecutive instances of the character, a comma, that I am using for my delimiter. Here's a sample line:
    The,lazy,fox,,jumped,,,over,the,,,moon,,,,,
    So, if my string has values for each field that the tokenizer looks at, I have no problems, but if there are two or more commas (delimiters) in sequence, it breaks the tokenizer.
    So what I'd like to do barring a better/simpler solution is to print "N/A" or something if there is no data in that token and then continue on to assign each (valid) token to a String variable.
    Thanks...

    Like warnerja suggested/mentioned: try String's
    split(...) method:
    String s =
    "The,lazy,fox,,jumped,,,over,the,,,moon,,,,,";
    String[] tokens = s.split(",+");
    for(int i = 0; i < tokens.length; i++) {
    System.out.println("Token "+(i+1)+" =
    "+tokens);
    Except get rid of the "+" part, as that just makes it eat the empty tokens. Just use s.split(",")                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • String substitution question

    Hello there,
    I have some SQL statements, such as:
    CREATE Table1 ( column1 INTEGER NOT NULL, column2 VARCHAR(20), column3 VARCHAR(30) )
    INSERT INTO Table1 (column1, column2, column3) VALUES (?, ?, ?)where I want to put the names of the columns in square brackets, i.e. substitute the column1, column2 and column3 by [column1], [column2] and [column3], respectively.
    For the INSERT case, I have noticed that one should handle strings occuring after an opening bracket "(" until a comma and after a comma "," until another comma or a closing bracket except the case when there is a ? before the comma, but the CREATE case is trickier...
    Could you please help me out with this? Thanks in advance.

    Thank you very much for your answers!
    I would like to once again thank Monica for her friendly attitude and her willingness to help! I have not followed all of her suggestions exactly, but they have indeed helped me much.
    I am glad to see that the SUN guys have fixed the forum formatting, so that you can read my solution easier. Any improvement suggestions or comments are, as always, most welcome.
    // Sample solution for the CREATE statement:
    String cStmt = "CREATE Table1 (column1 INTEGER NOT NULL, column2 VARCHAR(20), column3 VARCHAR(30))";
    int fw = 0; String new_cStmt = "";
    new_cStmt = cStmt.substring(fw, (fw=cStmt.indexOf("("))) + "( [" +
    cStmt.substring( fw+1, (fw=cStmt.indexOf(' ', fw+1)) ) + "] " +
    cStmt.substring( fw+1, (fw=cStmt.indexOf(",", fw+1)) );
    while(cStmt.lastIndexOf(",") > fw)
      new_cStmt += ", [" + cStmt.substring( fw+2, (fw=cStmt.indexOf(' ', fw+2)) ) + "] " +
    cStmt.substring( fw+1, (fw=cStmt.indexOf(",", fw+2)) );
    new_cStmt += ", [" + cStmt.substring( fw+2, (fw=cStmt.indexOf(' ', fw+2)) ) + "] " + cStmt.substring(fw+1);
    System.out.println(">> New CREATE statement: " + new_cStmt + " <<");
    // Sample solution for the INSERT statement:
    String iStmt = "INSERT INTO Table1 (column1, column2, column3) VALUES (?, ?, ?)";
    int fw = 0; String new_iStmt = "";
    new_iStmt = iStmt.substring(fw, (fw=iStmt.indexOf("("))) + "( [" + iStmt.substring( fw+1, (fw=iStmt.indexOf(",")) ) + "], ";
    // Relevant examination till first closing bracket in the INSERT statement
    while(iStmt.lastIndexOf("VALUES") > iStmt.indexOf(",", fw+1))
      new_iStmt += "[" + iStmt.substring( fw+2, (fw=iStmt.indexOf(",", fw+1)) ) + "], ";
    new_iStmt += "[" + iStmt.substring(fw+2, (fw=iStmt.indexOf(")"))) + "] )" + iStmt.substring(fw+1);
    System.out.println(">> New INSERT statement: " + new_iStmt + " <<");

  • String function question

    In Sybase, I could use "LEFT" or "RIGHT" to return X number of characters in a string. Does PL/SQL have a similar function?

    Hi,
    Solomon Yakobson wrote:
    ... Well, much better way is:
    to_char(grade_level,'00')
    I think you meant
    to_char(grade_level,'fm00')To those who don't understand:
    TO_CHAR leaves room for a minus sign when you use a second argument like '00', and the result will be a three-character string, starting with a space, e.g. ' 01'. Adding 'fm' to the second argument tells TO_CHAR not to include the extra space.

  • Cyrillic string conversion question

    Hello,
    First time here...
    I would like to know if there is a way to convert a text string from cyrillic to latin. Should I use a function?
    Edited by: user12099545 on 2009-10-22 5:38

    I have insufficient privileges to create the function so I'm going to look for someone else to create it so that I can use it. I've added additional letters and now it looks like this:
    CREATE FUNCTION cyrillic_to_latin_spelling(p_cyrillic VARCHAR2)
    RETURN VARCHAR2 IS
    TYPE v_spelling_type IS TABLE OF VARCHAR2(3) INDEX BY VARCHAR2(1);
    v_spelling_tbl v_spelling_type;
    v_str VARCHAR2(4000);
    v_char VARCHAR2(1);
    BEGIN
    v_spelling_tbl(' ') := ' ';
    v_spelling_tbl('А') := 'A';
    v_spelling_tbl('Б') := 'B';
    v_spelling_tbl('В') := 'V';
    v_spelling_tbl('Г') := 'G';
    v_spelling_tbl('Д') := 'D';
    v_spelling_tbl('Е') := 'E';
    v_spelling_tbl('Ж') := 'Z';
    v_spelling_tbl('З') := 'Z';
    v_spelling_tbl('И') := 'I';
    v_spelling_tbl('Й') := 'I';
    v_spelling_tbl('К') := 'K';
    v_spelling_tbl('Л') := 'L';
    v_spelling_tbl('М') := 'M';
    v_spelling_tbl('Н') := 'N';
    v_spelling_tbl('О') := 'O';
    v_spelling_tbl('П') := 'P';
    v_spelling_tbl('Р') := 'R';
    v_spelling_tbl('С') := 'S';
    v_spelling_tbl('Т') := 'T';
    v_spelling_tbl('У') := 'U';
    v_spelling_tbl('Ф') := 'F';
    v_spelling_tbl('Х') := 'H';
    v_spelling_tbl('Ц') := 'CH';
    v_spelling_tbl('Ч') := 'CH';
    v_spelling_tbl('Ш') := 'SH';
    v_spelling_tbl('Щ') := 'SH';
    v_spelling_tbl('Ъ') := 'A';
    v_spelling_tbl('Ь') := '';
    v_spelling_tbl('Ю') := 'IU';
    v_spelling_tbl('Я') := 'YA';
    FOR v_i IN 1 .. NVL(LENGTH(p_cyrillic), 0) LOOP
    v_char := SUBSTR(p_cyrillic, v_i, 1);
    v_str := v_str || v_spelling_tbl(v_char);
    END LOOP;
    RETURN v_str;
    END
    Edited by: harkon on 2009-10-23 0:07
    Edited by: harkon on 2009-10-23 0:08

  • Quick String / char  question

    Hi, i have to write a encrytion method for a assignment, it must take a string, move the characters on by a set number given by the user and return the result.
    public class Encryption
        int key;
        public Encryption(int k)
            key = k;
    public String encrypt(String si)
    si = si.toUpperCase();
    int i = 0;
    for (int index = 0; index< si.length(); index++);
    char c = si.charAt(i);
    int n = c - 'A' + key;
    char a = (char)(n + 'A');
    return si ;
    }it compiles, but what i need to know is how to i get my new chars (that have been moved the set amout) back into a string that is returned to the user, as i cant seem to find the code i need to do this???

    String result = "";
    Each time through the loop, you will want to add it to the result
    result = result + a;This is poor adviceimport java.io.*;
    public class Encryption{
       public static void main(String[] args) {
          new Encryption();
       Encryption(){
          String toEncyrpt = "The quick brown fox jumps over the lazy dog";
          int key = 0;
          try{
             BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
             System.out.print("Enter a number for the encryption key ");
             key = Integer.parseInt(br.readLine());
          }catch(IOException e){}
          String encrypted = encrypt(toEncyrpt, key);
          System.out.println("Encrypted string : "+ encrypted);
          String decrypted = decrypt(encrypted, key);
          System.out.println("Decrypted string : "+ decrypted);
        public String encrypt(String s, int k){
           StringBuffer sb = new StringBuffer();
           for(int i=0; i<s.length(); i++) {
               int temp = (int) s.charAt(i)+k;
               sb.append((char)temp);
           return sb.toString();
        public String decrypt(String s, int k){
           StringBuffer sb = new StringBuffer();
           for(int i=0; i<s.length(); i++) {
               int temp = (int) s.charAt(i)-k;
               sb.append((char)temp);
           return sb.toString();
    }

Maybe you are looking for

  • NOTHING_FOUND exception while running a webdynpro application

    I have a webdynpro view which has two containers. one of them contains a view with some ui elements and the other is to display an ALV table . When i run my application, i get a NOTHING_FOUND exception. is it something in the system or i am doing som

  • Converting .mov to .cdr for viewing

    Hello all, I have a bunch of .mov files of training videos, but I can't play them on my computer screen and use the program at the same time, so I want to play them on my standard DVD player on a TV. What is the process through which I can get my .mo

  • Missing files in PSE8?

    Hi I have PSE8 on a Windows XP machine.  I wanted to install an action and was told to put it in my C://Documents and Settings>all users> application data>Adobe>Photoshop Elements 8> Photo Creations>Photo Effects folder. I followed the instructions b

  • E mail... I dont like the new system....​And why did i have to change?

      Your new e mail system is a joke...

  • Regarding caching mechanism - Pls respond ASAP.

    Hi All, I am trying to apply "purging of cache" on daily basis in my application because it is on transactional database. How could i proceed. I think if i am adding a event polling table and set the frequncy to 1 day then i can achieve that. But is