Comparing 2 strings in if statement

Hi All,
I want to compare two strings in if statement. When I use "==" then its throwing error that expected number and got string. Can anyone please let me know how can we compare two strings in an IF statement?
Thanks in advance

The OP doesn't state what release he's on.
The functions @LIKE and @MBRCOMPARE are 11.1.2 and up only.
OP, if you're at a lower release, I've faced this problem as well in 11.1.1.3. Here's an older thread that detailed how I got around it for a client:
Re: How to compare two strings in calc script?
It really wasn't hard to do and the performance, in the limited context I was using it in, was fine.
Regards,
Cameron Lackpour

Similar Messages

  • Comparing Strings with "If" statements : help please. :-)

    I have an assignment for class... and having lots of trouble trying to figure out what I did wrong. I cannot find a solution.. if anyone can help me with this, it'd be much appreciated.
    Assignment Write a program to allow the user to calculate the area and perimeter of a square, or the area and circumference of a circle, or the area of a triangle.
    To do this, the user will enter one of the following characters: S, C, or T. The program should then ask the user for the appropriate information in order to make the calculation, and should display the results of the calculation. See the example program execution shown in class.
    The program should use dialog boxes.
    When expecting an S, C, or T, the program should reject other characters with an appropriate message.
    Get extra points for allowing both the uppercase and lowercase versions of a valid character to work. Name the program ShapesCalc.java.My error codes are
    incomparable types: java.lang.String and Char
    cannot find symbol variable output
    incomparable types: java.lang.String and Char
    incomparable types: java.lang.String and CharI've asked a friend and they said something about Strings cannot be compared in "If" statements... if that is the case.. how is this supposed to be arranged? If you can point me in the right direction, I will be very grateful! :-)
    What I have created so far
    import javax.swing.JOptionPane;
    public class ShapesCalc {
        public static void main(String[] args) {
          //Enter S,C, or T
          String input = JOptionPane.showInputDialog("Enter S,C, or T");
          //If Statements
          //Square
          if (input == 'S'){
               String lengthu = JOptionPane.showInputDialog("Enter length of a square");
               double length = Double.parseDouble(lengthu);
               double area = length * length;
               double perimeter = length * 4;
               String ouput = "The area is " + area + " and the perimeter is " + perimeter;
               JOptionPane.showMessageDialog(null, output);}
          //Circle
          else if (input == 'C'){
               String radiusu = JOptionPane.showInputDialog("Enter the radius of a circle");
               double radius = Double.parseDouble(radiusu);
               double area = 3.14159 * radius * radius;
               double circumference = 2 * 3.14159 * radius;
               String output = "The area is " + area + " and the circumference is " + circumference;
               JOptionPane.showMessageDialog(null, output);}
          //Triangle
          else if (input == 'T'){
               String baseu = JOptionPane.showInputDialog("Enter the base of a triangle");
               double base = Double.parseDouble(baseu);
               String heightu = JOptionPane.showInputDialog("Enter the height of a triangle");
               double height = Double.parseDouble(heightu);
               String output = "The area is " + (base * height) / 2;
               JOptionPane.showMessageDialog(null,output);}
          //Error Message
          else {
               String error = "Incorrect variable please enter S,C, or T only.";
               JOptionPane.showMessageDialog(null,error);}
          //Signature
          String signature = "Rodriguez, Markos has compiled a Java program.";
          JOptionPane.showMessageDialog(null,signature);
    }Edited by: ZambonieDrivor on Feb 22, 2009 6:52 PM

    ZambonieDrivor wrote:
    How would I go about on the extration of a single char from a String to make it comparable, I don't quite understand this part.Read the [Java API|http://java.sun.com/javase/6/docs/api/] for the String class and see what methods it has.
    I will convert the == to equals() method.If you want to compare primitives (ints, chars etc) then using == is fine. Only when comparing objects do you use the equals method.

  • How to compare string in a case-insensitive manner using JavaScript?

    Hello everyone,
    Now I have a javascript to compare checkbox's value with user's input, but now seems it only can compare case-sensitively, does some one know if there is a function in javascript that it can compare string case-insensitively ?
    Here is my script :
    function findOffice(field)
    var name;
    name=prompt("What is the office name?");
    var l = field.length;
    for(var i = 0; i < l; i++)
    if(field.value==name)
    field[i].checked=true;
    field[i].focus();
    field[i].select();
    break;
    <input type="button" name="Find" value="Find And Select" onClick="findOffice(form1) >
    Thanks in advance !
    Rachel

    Thank you so much, I already solved the problem with your advice.
    You really have a beautiful mind, :-).
    I appreciate your help !
    Rachel

  • Compare blob in SQL statement

    Hi,
    Is it possible to compare blob in SQL statement?
    Example:
    Table1 (id number
    image long raw);
    Table2 (name varchar2
    pic long raw);
    select id, name from table1, table2
    where image = pic

    Hi,
    Try the following and see if it works :
    I have TEXT in the LONG RAW column and not image
    files.
    Method I
    You can use PL/SQL to check if the 2 Long RAW Columns are
    identical or not :
    NOTE :- PL/SQL however has a limitation of processing
    data size less than 32k in size. If the
    Long Raw column exceeds 32k in size then PL/SQL
    cannot be used.
    SQL> desc temp9;
    Name Null? Type
    ID NUMBER
    COL1 LONG RAW
    SQL> desc temp9a;
    Name Null? Type
    ID NUMBER
    COL1 LONG RAW
    SQL> @t
    Id = 1, Long Raw is not the same
    Id = 2, Long Raw is the same
    PL/SQL procedure successfully completed.
    SQL> select id from temp9;
    ID
    1
    2
    SQL> get t
    1 Set ServerOutput On Size 999999;
    2 Declare
    3 CURSOR c1 Is
    4 Select id, col1
    5 from temp9;
    6 xCol1 Temp9a.Col1%Type;
    7 BEGIN
    8 For x In c1 Loop
    9 Select col1
    10 Into xCol1
    11 From temp9a
    12 Where id = x.id;
    13 If ( x.col1 = xCol1) Then
    14 Dbms_Output.Put_Line ('Id = ' || x.id || ', Long Raw is the same');
    15 Else
    16 Dbms_Output.Put_Line ('Id = ' || x.id || ', Long Raw is not the same');
    17 End If;
    18 End Loop;
    19 END;
    20* /
    Method II
    You can create a Database function for the above script and use it within
    your SQL .
    -- Shailender Mehta --

  • Compare date in SQL statement

    yup.. how can i compare date in SQL statement??
    pls give me a completed example.

    I'd think this is a formatting problem. Why not try:
    PreparedStatement ps = myConnection.prepareStatement(
    "SELECT * FROM Receipt WHERE to_date(Date) > ? ");
    ps.setDate(1,TodayDate);
    ResultSet rs = ps.executeQuery();
    HTH,
    Ken

  • Comparing string in select query

    Hi,
    select single *
           from mara
           where <b>matnr = wa-matnr</b>.
    Here matnr is char18. Can we compare string like this?
    When <b>wa-matnr</b> is in <b>lower case</b> it is setting sy-subrc = 4, even though the matnr exists in mara. When converted to upper case and used it is setting sy-subrc = 0.
    Is there any other solution for the problem? I have checked out with matnr's conversion routine. It is also not working.

    just try  dat way...
    <b>ex...</b>
    data:wa_matnr like mara-matnr.
    data:wa_matnr1 like mara-matnr.
    data: gv_matnr like mara-matnr.
    wa_matnr = 'comptest'.
    CALL FUNCTION 'TERM_TRANSLATE_TO_UPPER_CASE'
      EXPORTING
       LANGU                     = SY-LANGU
        TEXT                     = wa_matnr
    IMPORTING
       TEXT_UC                   = wa_matnr1
    EXCEPTIONS
      NO_LOCALE_AVAILABLE       = 1
      OTHERS                    = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    select single matnr
    from mara into gv_matnr
    where matnr = wa_matnr or matnr = wa_matnr1.
    write : gv_matnr.

  • Execute an string as select statement

    Hi,
    I have a problem:
    I'm working with an older oracle verion (7.x??). I want to create a dynamic select statement. I create a string, e.g. v_sql_string, and want the database to execute it. What possibilities do I have to do this?
    Thanks in advance
    Mathias

    Yes,
    I went through the documentation, but it's only working with cursors.
    For better comprehension:
    This is the string:
    'select count(*) from invoice where sup_no ' || op_sup_no || ' v_sup_no and trpt_code ' || op_trpt_code || ' v_trpt_code and ship_no ' || op_ship_no || ' v_ship_no'
    I want to set the operators (op_xxx) dynamiclly. Isn't there something like RUN or EXECUTE, where I only have to pass a string, and the statement is executed ...
    But I don't know how ...
    Mathias

  • Public static final Comparator String CASE_INSENSITIVE_ORDER

    in this declaration..
    public static final Comparator<String> CASE_INSENSITIVE_ORDER
    what does <String> mean?
    thanks!

    what does the Comparator do. Look at the API and you would see the following description about the compare method.
    public int compare(Object o1,
    Object o2)Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
    The implementor must ensure that sgn(compare(x, y)) == -sgn(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)
    The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.
    Finally, the implementer must ensure that compare(x, y)==0 implies that sgn(compare(x, z))==sgn(compare(y, z)) for all z.
    It is generally the case, but not strictly required that (compare(x, y)==0) == (x.equals(y)). Generally speaking, any comparator that violates this condition should clearly indicate this fact. The recommended language is "Note: this comparator imposes orderings that are inconsistent with equals."
    Now your question is about what <String> is in your declaration. It is the type of the objects which are going to be compared.

  • Compare Strings using JSTL

    How can I compare strings with JSTL? One string is a stored date and the other is a generated date. My goal is to set the correct date in a dropdown menu with date values (yyyy-MM-dd) by comparing the current date with the stored.
    Code
    <%
    Calendar cal = Calendar.getInstance(timezone, locale);
    Format fm = new SimpleDateFormat("yyyy-MM-dd");
    String date2 = (String) fm.format(cal.getTime()); %>
    <c:set var="date1" value="${mb.date}" />   // from database lookup (MySQL Date)
    <p><c:out value="${date1}"/>=<%=date2%>:<c:out value="${date1 == '<%=date2%>' }" /></p>The result is:
    2004-08-03 = 2004-08-03 : false

    well, about this:
    <%
    Calendar cal = Calendar.getInstance(timezone, locale);
    Format fm = new SimpleDateFormat("yyyy-MM-dd");
    String date2 = (String) fm.format(cal.getTime());
    pageContext.setAttribute("date2",date2);
    %>
    <c:set var="date1" value="${mb.date}" />   // from database lookup (MySQL Date)
    <p><c:out value="${date1}"/> .equals <%=date2%>:<c:out value="${date1eq date2}" /></p>I try to use the EL 'eq' like you would use '.equals()' in regular java, and EL '==' like regular java '==' And since we are comparing Strings here, which are objects, we would use .equals rather than ==, since == compares refernce and .equals compares value...

  • Simple question - compare Strings with SSIS expression language

    SSIS variables - strOne = YES, strTwo = YES. I want to compare strings using ssis expression language (ie inside a variable's expression box, constraint of task flow arrow etc).
    Will @strOne == @strTwo be true ? I hope its not like programming languages where you need to do
    @strOne.Equals(@strTwo) instead of ==. Also is @strOne == "YES" true ?

    ([User::strOne] == [User::Strtwo] ? True : False)
    The third variable created should be of type boolean if you're using above expression. if its of type int return 0 and 1 instead of False and true
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Concatination of string to select statement

    hi all,
    pl help me out.
    i want to concatenate string to select statement like
    create or replace procedure my_proc(p_sal number)
    as
    v_name varchar2(20);
    ssql varchar2(4000);
    begin
    ssql := ' ';
    select ssql || ' '|| select emp_name
    into v_name
    from employees
    where sal =p_sal;
    end;
    but it is giving error .
    pl correct it.
    thanks
    pavani

    Pavani,
    Still not clear.
    "Multiple conditions" sounds like you are trying to build predicates in the where clause, but in your example it looks like you are trying to build a select clause. Also your parameter is p_sal so the where clause "sal = p_sal" is fixed.
    The real question is WHY you want to "write multipul conditions"? WHY you want to "store it in a string .and then concatenate the string to next condition so on"?
    Regards,
    Rob.

  • Compare string in different line in text file

    I am new to java and I need a simple example to compare string in file text by for loop
    file.txt:
    A78802 D06VAIS060253113 WKNEUP751346577450
    A77802 D06VAIS060253113 WKNEUP751346577450
    A76802 D06VAIS060253925 WKNEUP751346577450
    A78802 D06VAIS075253698 WKNEGE226375082796
    A73802 D06VAIS116253222 WKNEFB227345305299
    dataString = TextIO.getln();
    A=dataString.substring(25,42);
    B=dataString.substring(195,203);
    C=dataString.substring(171,186);
    I WANT COPMPARE IN LINE 1 POSITION 20 TO LINE 2 POSITION 20 BY LOOPS ALL THE LINE IN TEXT FILE

    what have you tried so far?
    Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, either use the "code" button at the top of the forum Message editor or place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
    &#91;code]
      // your code block goes here.
    &#91;/code]

  • Compare string in JSTL

    Hi all,
    I have   <c:set var="status" value="${found.studentStatus}"/> inside loopI want to call it outside the loop and compare string
    <c:if test="${status.equals("A")}">
    do something
    </c:if>
    But I get bug equals symbol expect, what is wrong?

    EL is not java. The same rules don't apply. You actually do want to use the equals operator here. It ends up invoking the java .equals method in the end.
    To make it explicit:
    <c:if test="${status == 'A'}">
    //or
    <c:if test="${status eq 'A'}">Cheers,
    evnafets

  • Sort / compare Strings   SOS ... ___ ...

    Hi, sorry I'm novice in Java, and I'm trying to make kind of bubble sort on String MyArray[]. God ! I just found out that I can't compare Strings i.e. Objects like:
    if ( MyArray[i] > MyArray)...
    Can anybody recommend me a not too complicated solution, preferebly without imports..
    Thanks
    Mario

    Hi.
    String.compareTo(String anotherString) is what you need. Have a look at http://java.sun.com/j2se/1.4/docs/api/java/lang/String.html#compareTo(java.lang.String)
    Regards,
    Lance
    Lance Walton - [email protected]
    Team In A Box - Software without Tragedy
    http://www.teaminabox.co.uk

  • C:choose for comparing strings

    Hi,
    I am trying to apply alternate styles to table rows using JSTL. When I am comparing strings it always falls into the 'otherwise' block. I guess I either have a silly error or there is something I am missing. When I output the string with the c:out it is set to the value 'data_row_white', which is what I find confusing as the test should prove true.
    I have also tried using the 'eq' operator to compare.
    Any help is appreciated.
    <c:set var="col_css" scope="page" value="data_row_white" />
            <c:forEach items="${requestScope['local_catalogue_list']}" var="item">
                <tr class="${col_css}">
                    <td class="no_top_no_right"><a href="javascript:viewCatalogue('${item.catalogueID}');">${item.catalogueName}</a></td>
                    <td class="no_top_middle">${item.status}</td>
                    <td class="no_top_no_left">${item.versionID}</td>
                </tr>
                <c:out value="${col_css}" />
                <c:choose>               
                    <c:when test="${col_css == 'data_row_white'} ">
                        <c:set var="col_css" scope="page" value="data_row_gray" />
                    </c:when>
                    <c:otherwise>                   
                        <c:set var="col_css" scope="page" value="data_row_white" />
                    </c:otherwise>
                </c:choose>
            </c:forEach>

    Using the ternary operator in EL which intercepts on the loop index is a much better/clearer/quickier way to alternate table rows.
    Basic example:    <table>
            <c:forEach items="${users}" var="user" varStatus="loop">
                <tr class="${loop.index % 2 == 0 ? 'even' : 'odd'}">
                    <td>${user.id}</td>
                    <td>${user.username}</td>
                    <td>${user.email}</td>
                    <td>${user.age}</td>
                </tr>
            </c:forEach>
        </table>

Maybe you are looking for