Compare the last Char to the First Char in a Sting

Hello, this should be easy but I'm having problems so here goes.
I get the user to input a Stirng and I want it to compare the last Char to the first Char. I have writen this but StartWith can take a Char?
public static void main(String[] args) {
        // TODO code application logic here
        String strA = new String();
        int length = 0;
        char lastLetter;
        System.out.println("Please input your first String: ");
               strA = EasyIn.getString();
             length = strA.length()-1;
               lastLetter = strA.charAt(length);
       if( strA.endsWith(lastLetter))
            System.out.println("The first letter matches the last");
       else
                   System.out.println("They Don't match");
}I have tried lastLetter.endsWith(strA) but that dosn't work some thing to do with it not taking Char
From reading you can go strA.startWith("R") and that would look for R but you can't put a char in that would be a single letter.
I also tried to lastletter to a string but then charAt wouldn't work.

fixed it I used substring as its a string object any one recomend a better way let me know
public static void main(String[] args) {
        // TODO code application logic here
        String strA = new String();
        int length = 0;
        String lastLetter;
        System.out.println("Please input your first String: ");
               strA = EasyIn.getString();
             length = strA.length()-1;
               lastLetter = strA.substring(length);
       if( strA.startsWith(lastLetter))
            System.out.println("The first letter matches the last");
       else
                   System.out.println("They Don't match");
}

Similar Messages

  • How to compare the first and last characters of strings?

    lets say we have a name column with values;
    c1
    Antu Anamentu
    Steven Smith
    Since A=A and U=U for the first value we need a TRUE and FALSE for the second value SQL. Is this possible to do with REGEXP functions on 10gR2.
    Thank you.

    Hi Frank,
    Just minor correction: REGEXP_LIKE (Name1, '^(.).*(.) \1.*\2$') ;
    Explanation: ^(.) =>^ specifies the next char is first char
                                . dot specifies single character
                               ()  defines group which can be backrferenced
                       .* => Any number of characters as we want only first and last character
                      (.)  => (.)space The space signifies that we want to remember last char of first word or char before space
                       \1 => It recalls first group which we saved for backreference using (.)
                       .* => Any number of chars
                      \2 =>  It recalls first group which we saved for backreference using (.)
                       $ => It specifies the char before this is last charHope it clarifies :)
    SQL> WITH t AS
    SELECT 'Antu Anamentu' Name1 FROM DUAL UNION ALL
    SELECT 'Steven Smith' Name1 FROM DUAL
    SELECT Name1
    FROM t
    WHERE REGEXP_LIKE (Name1, '^(.).*(.) \1.*\2$')  ;
    NAME1
    Antu Anamentu

  • Chunk expressions: Need the first and last char position from member.word[x]?

    I need to build a linear list of the string positions of the
    first and last character of each word in a string. For example if I
    have the string myPet = “DOG CAT FISH” then myList =
    [[1,3],[5,7],[9,12]]
    myPet.word[x] will let me access the individual words but
    I’m not sure how to get the char position of the beginning
    and end of each. Please help, it’s Friday and my brain has
    left for the weekend.

    Touche, Sean.
    "Sean Wilson" <[email protected]> wrote in
    message
    news:fqa8ap$bga$[email protected]..
    > Hi Craig,
    >
    > Your's fails if any word is repeated. Try it with "DOG
    CAT FISH DOG"
    >
    > This one seems to work, although there are probably more
    efficient ways to
    > go about it. A regular expression and the PRegEx xtra
    would certainly be
    > quicker, especially as the string gets longer
    >
    > on mGetWordBoundaries aString
    > -- basic error check
    > if stringP(aString) = 0 then return []
    > if length(aString) = 0 then return []
    >
    > lWhitespace = [SPACE, TAB, RETURN, numToChar(10)]
    > tStart = 1
    > tChar = aString.char[tStart]
    > repeat while lWhitespace.getPos(tChar)
    > tStart = tStart + 1
    > tChar = aString.char[tStart]
    > end repeat
    >
    > lPositions = []
    > repeat with w = 1 to aString.word.count
    > tEnd = tStart + aString.word[w].char.count - 1
    > lPositions.append([tStart, tEnd])
    > tStart = tEnd + 1
    > tChar = aString.char[tStart]
    > repeat while lWhitespace.getPos(tChar)
    > tStart = tStart + 1
    > tChar = aString.char[tStart]
    > end repeat
    > end repeat
    > return lPositions
    > end

  • To skip the first two Digits of the Char in Query

    Iam using County code which is the attribute of Vendor in free-chars of my query. In back-end iam doing some enhancements for this county code and populating the county codes values with region. (For example if the country code value is 021 in back end iam populating by concatenating with region value. so the value in the back-end is 05021.)
    When i run the query the key of county code value i see is 05021. But i need to skip the first two digits in county code and should display in the result. Is there any way to skip the first two digits for the county code values.
    Thanks in Advance
    Sudhakar

    Hi Sudhakar,
    Pls go through the link:
    Remove the last two charecters from right
    Thanks and Regards,
    Ramki

  • Strange behaviour of StringBuilder. Does not append the last char buffer.

    Below is the source code I am using to read a .gz file and convert it into plain text. I am using StringBuilder to store the whole plain text as a string and also writing the plain text to a file on disk. The writing on disk works perfectly fine, but for some weird reason, the StringBuilder leaves out the last part of the file (run it once and you'll see what I mean), when in fact both the StringBuilder and the OutputStreamWriter get their data from the same while loop.
    import java.util.zip.GZIPInputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.OutputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    public class ProblemInStringBuilder
    public static void main(String args[]) throws Exception
    String inFilename, outFilename;
    inFilename = "somefile.gz"; outFilename = "unzipped file.txt";
    GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(inFilename));
    InputStreamReader myInputStreamReader = new InputStreamReader(gzipInputStream);
    OutputStream out = new FileOutputStream(outFilename);
    OutputStreamWriter myOutputStreamWriter = new OutputStreamWriter(out);
    int len;
    char[] charBuf = new char[1024];
    StringBuilder builder = new StringBuilder();
    while ((len = myInputStreamReader.read(charBuf)) > 0)
    builder.append(charBuf);
    myOutputStreamWriter.write(charBuf,0,len);
    gzipInputStream.close();
    myInputStreamReader.close();
    myOutputStreamWriter.close();
    System.out.println(builder); // <-- problem here. Leaves out the last part of the file.
    }

    builder.append(charBuf);
    builder.append(charBuf, 0, len);From this error it seems to me you are getting extra characters at EOF (and possibly elsewhere), not missing characters.
    gzipInputStream.close();
    myInputStreamReader.close();Remove the first of those. The second one closes them both.

  • How to delete the last char in a String?

    i want to delete the last char in a String, but i don't want to convert the String to a StringBuffer or an array, who knows how to do?

    Try it in this way
    String MyString = "ABCDEF";
    MyString = MyString.substring(0,MyString.length()-1);

  • Cutting last char in the XI

    hello experts
    I have a scenario RFC2WS and sending
      <?xml version="1.0" encoding="UTF-8" ?>
    - <rfc:ZRFC_POLICY_OR_INSURANCE xmlns:rfc="urn:sap-com:document:sap:rfc:functions">
      <PASSWORD>kf001</PASSWORD>
      <USERNAME>kfirg001</USERNAME>
      </rfc:ZRFC_POLICY_OR_INSURANCE>
    but in the XI I am recieving
      <?xml version="1.0" encoding="UTF-8" ?>
    - <rfc:ZRFC_POLICY_OR_INSURANCE xmlns:rfc="urn:sap-com:document:sap:rfc:functions">
      <PASSWORD>kf00</PASSWORD>
      <USERNAME>kfirg00</USERNAME>
      </rfc:ZRFC_POLICY_OR_INSURANCE>
    it is always cutting the last char in the username\password. in the RFC it is defined as a String.
    I couldnt find out why it is cutting the last char and help would be great.
    Thanks
    Kfir

    Hi,
    Is it possible for you to send it with Filed type as CHAR instead of String..
    In RFC source code you could handle this kind of conversion.
    Try with CHAR...instead of string.
    Thanks
    Swarup

  • Char displaying only the first three characters in the cube

    Hi Experts
    I have a char  with lenth 60 and it's active.I am updating this char via the update routine whereby i am reading data from an active table of an ODS as i update in the update rules.
    But surprisingly,once the load is succesful and complete,upon checking the data in the active table it's displayin the way it should be the problem comes in when I view the data on the cube which displays only the first three chars even if the descriptionis a 60 character field.
    Please help

    Hi Herbert,
    Have you checked in the infosource or transfer rules, what is the length of the infoobject, if you are loading the data to PSA, please check there it self, whether it is displaying 60 characters or only 3 characters.
    Thanks
    Sat

  • How to get the first 4 chars form a var ?

    Hi guys,
    How to get the first 4 chars form a var ?
    i.e  temp type num20 value '00000000000012345678'.
    how to move the first 4 chars to another var?
    thx in advance.

    hi
    use OFFESTS..
    example:
    var1 = '12345678'.
    var2 = var1+0(4).
    now var2 conatins '1234'.
    thx
    pavan

  • Deleting the last char of a string

    How can I Delete the last char of a string???
    example:
    asd@fdg@vvdfgfd@gdgdfgfd@gdfgdf@
    I want delete the last @!
    Tks in advance!

    hi,
    try this:
    lv_count = strlen(string).
    lv_count_last = lv-count - 1.
    replace string+lv_count_last(lv_count) in string by ' '.
    This should work.
    thnx,
    ags.
    Edited by: Agasti Kale on Jun 4, 2008 9:03 PM

  • Finding last char in the string

    Hi
    i need to find out whether the last char of a string is '/' (forward slash). please let me know if there's a FM to do that. Other post me the logic for this ASAP.
    thanks

    len = strlen(char).
    len = len - 1.
    if char+len(1) = '/'.
      *write ur code
    endif.
    chk this code
    REPORT ychatest.
    DATA : str(5) VALUE '123/',
           len TYPE i.
    len = STRLEN( str ).
    len = len - 1.
    IF str+len(1) = '/'.
      WRITE : '/ found'.
    ENDIF.
    <b>Reward points if helpful and close thrad if solved</b>
    Message was edited by: Chandrasekhar Jagarlamudi

  • The first 100 Chars in Struts

    Hi I am a novice struts user and I need HELP!
    I have a string Description in a vector with I then throw at the JSP. Here I am using c:out stuff to get it to print...BUT I need only the first 100 chars or so following by elipses...I know that there is a scriplet for a string but I can't figure out the command for a struts.
    Here is my code:
    <%@ page language='java'%>
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
    <html>
    <head>
    <title>Search Results</title>
    </head>
    <b> Results:</b><br><br>
    <c:forEach var="record" items="${SearchProgram}">
    <b> <c:out value="${record.acronym}"/> </b><br>
    <a HREF="https://enweb.mitre.org/program.do?programId=<c:out value=${record.programId "/>"><c:out value="${record.longName}"/><br>
    <a HREF="https://enweb.mitre.org/spo.do?spoPadId=<c:out value=${record.spoPadId"/>"> Mother SPO Homepage<br>
    <c:out value="${record.description}"/><br><br> <!-- THIS IS WHERE I PRINT DESCRIPTION-->
    </c:forEach>
    </html>

    No easy way to do this in JSTL/JSP code.
    Obviously you could use scriptlets record.getDescription().substring(0, 100)
    The better solution would be to populate the description (or maybe a short description?) field with the shortened value.
    ie add a method to your bean getShortDescription which gets the value you want.

  • Photosmart C7280 only takes the first 4 chars of the WPA Key

    When I try to set the WEP key on the printer it seems to truncate after the first 4 chars. Some one said that there is a way to reset the printer using a reset button - pressing this might fix the problem. 
    Any ideas on how I can printer to work again wireless? 

    How are you trying to enter the key?  What operating system?  What router are you using?
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • Detecting the first char inside string

    Hi,
    I search through all the String and char method but it doesn't seems to be any method to do this.
    Is there anyway I can detect the first char in a String
    Eg:
    @#@Hello!!
    Is there a method that allows me to detect H directly?

    I guess you mean the first character of a particular type - excluding '@' and '#'.
    morgalr wrote:
    There isn't a built in function like String.firstChar() that would give you the first character of any String. You can easily make one though.There is [String.charAt(int index)|http://java.sun.com/javase/6/docs/api/java/lang/String.html#charAt(int)] which returns the character at position index. This method can't read your mind though, so charAt(0) will return the very first character regardless of whether it is "good".
    In the Character class there is also a static method [isLetter(character)|http://java.sun.com/javase/6/docs/api/java/lang/Character.html#isLetter(int)] which reports "true" if the supplied character is a letter. There are lots of other methods in this class to report on the type of letter.
    Perhaps you could put these ideas together: write a loop to inspect each letter in turn until you come to one that is "good".

  • Not allowing a number as the first char in the username

    Is there a particular reason why I am not allowed to create a username with a number
    as the first character? Or is this something that can be changed? If so, how
    can I go about changing it? I have edited the UsermgmtTools.properties to say:
    "disallowFirstCharDigit: false", instead of true... and rebooted the portal, but
    it did not seem to make a difference. Any help in this would be greatly appreciated.
    Thanks

    Oh, I failed to change the field type to "text" in the insert
    record dialogue box as well.

Maybe you are looking for

  • How to read document in SQL

    I have an XMLDb install under 9iR2. When I put a document, let us say a Word 2003 .xml document inside XMLDB via webdav or ftp it is stored somewhere in the database. Now I want to access the file contents from SQL as a whole, that is put the file co

  • Sending texts problem

    I got the blackberry curve a few days a go and some of my texts are not being received when sent to only certain numbers. Most of my texts get the black check mark and a D when they are sent but only certain phone numbers my phone shows the black che

  • UH-OH, File Vault BIG trouble

    After turning on File Vault, my Macbook has been sitting at "deleting old home folder" for the better part of two hours. It's not very big at all, should be just a few minutes to delete. What next? Pull the plug? It won't shutdown or restart. HELP!

  • Can't locate serial number on my packaging

    I have Photoshop Elements 13 in the box and am unable to locate a valid serial number on the packaging, DVD envelope, or the insert.  The insert says the number should start with 1057 and should be on the DVD "case."  However, there is no case, only

  • Random 401 errors - Kerberos + Reporting Server

    We have a portal with Reporting Server in SharePoint mode and deployed our reports to SharePoint. Reports run in integrated security mode, we configured Kerberos. (Reporting server configured as RSNegotiate, added SPN's, etc.) Everything seems to be