How can I select the last 2 chars of a string

Hello all,
I am trying to select the last 2 characters of a string to match them to another string. This is for a Poem generator that contains 20 or so words and I have to pick 2 words at random, them look at the last 2 characters to see if they match in each string. Say "Plain" and "Rain" would match because they both have "in" at the end. The length of each word could vary. I don't want this doing for me just what Method should I be looking at.
Thanks.

hi,
try this:
public class StringTest {
     public static void main(String args[]) {
          StringTest obj = new StringTest();
          obj.same();
     void same() {
          String rain = new String("Rain");
          String plain = new String("Plain");
          int rainLength = rain.length();
          int plainLength = plain.length();
          if(rain.substring(rainLength-2).equals(plain.substring(plainLength-2))) {
               System.out.println("same");
          else {
               System.out.println("different");
}you can use the length method to get the length of a string and then use the substring method, passing it length-2, so get the last 2 chars.

Similar Messages

  • How can I erase the last char of string

    I have a string tha is printing as following
    129.111.13.1.
    I want to erase the last "." can somebody helpme?
    Thanks

    You will have to create a new String. Then you can get the string length. Then you will need to to use a substring to get the positions you want.
    Something like this
    String Orginal = "129.111.13.1.";
    String new_orginal = null;
    int num;
    num = Original.length();
    new_orginal = Original.substring(0,num-1);
    I hope it helps

  • 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

  • How can we update the last synchronization date and time..on SUP in sccm 2012 R2

    Hi,
        Can you any one please guide me how can i update the last  synchronization date & time in SUP on SCCM2012 r2 , some how its updated as future date and when ever i try to synch the SUP with disconnected WSUS its shows in the wsyncmgr.log 
    "Wakeup for a polling cycle " and  " Wakeupby inbox drop" and "Wakeup by SCF change"  
    Thanks 
    Balaji K

    You'll probably have to call CSS on this one as this not normal by any means. The messages you noted above are completely normal but if that's all you are seeing then there's an issue.
    Have you reviewed wcm.log and wsusctrl.log?
    Jason | http://blog.configmgrftw.com | @jasonsandys

  • 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);

  • How can I get the last updated email address of the customer ??

    Dear All,
    Please let me know, How can I get the last updated email address of the customer ??
    Also, I am trying to read CDHDR table where OBJECTCLAS is ADRESSE, however what value should be passed into OBJECTID field, looks like it is ADRNR with a Suffix BP.
    Please confirm me what value should be passed into OBJECTID field.
    Thank you.
    Anitha

    Hi Anitha,
      Check if this is something that helps you:
    Change documents in BAS
    CDHDR
    address type 1
    objectclass = ADRESSE             
    objectid = addrgroup + addrnumber     (ADRC-ADDR_GROUP + ADDRNNUMBER) !!
                     'BP  000xxxxxx'
    private address (address type 2)
    objectclass = ADRESSE2
    objectid =  'BP  000xxxxxx000yyyyyyy'   
                            persnumber+adrnr private
    address type 3
    objectclass = ADRESSE3
    objectid =  'BP  000xxxxxx000zzzzzzz'
                              persnumber +comp.address
    The above details is from the link: http://wiki.sdn.sap.com/wiki/display/ERPLO/LO-MD-BP
    Regards,
    Swarna Munukoti

  • How can I reference the last value in a column?

    How can I reference the last value in a column? For example, today I want the value of A1 to appear in another cell. Tomorrow, I will add a row and want to reference A2, next day A3, and so forth.

    Now I got it:
    =OFFSET(A1,COUNT(A)-1,0)

  • How can i check the last location of iphone when it was on?

    I left my iphone in a taxi, but i found the taxi's home, i went to his home and i told him to give me back my iphone but he told me that he never seen iphone in his taxi.
    the iphone was on when i left it in the taxi and it was still on till 4 hours after i left it, probably he found the iphone and went to his home so i just wanna check the last location of iphone, if it shows in his home area so i will be sure that he got the iphone and then i contact the police to take it back but otherwise i can not do anything cause he says i haven't found it.
    plz plz help me

    it was active when i lost it and i went to icloud website, but it shows offline. that means that it is off.
    i just need to know if the iphone keeps recording of location where you go and how can i see the last location of iphone when it was on.

  • I'm trying to install an update to itunes that downloaded but can't complete installation as its trying to install onto D: drive. I don't have a D drive and i'm not given option of selecting the drive to install on. How can i select the drive that i want

    I'm trying to install itunes but can't complete installation as its trying to install onto F: drive. I don't have a F drive and I'm not given option of selecting the drive to install on. How can I select the drive that i want to install on?

    Hi,
    How do you connect the printer to the XP machine ? If USB, you need to make that machine as a Print server. Please try this:
       http://techtips.salon.com/make-windows-computer-pr​int-server-11914.html
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • How can I see the last location of a now dead ipod touch 4G that had find my iphone turned on?

    How can I see the last location of a now dead ipod touch 4G that had find my iphone turned on? I can see my macbook but I cant see the last location of my ipod touch. I lost it a few weeks ago and figured it would show up. But it has not and I need it again for my job. Please help.

    There is nothing you can do now. There are apps available from the app store that would give you that information if installed before it was lost/stolen.

  • I have an Ipod touch updated to last available ios 4.2.1. How can I get the last compatible versions of the apps?

    I have an Ipod touch updated to last available ios 4.2.1.
    How can I get the last compatible versions of the apps?
    In the appstore there are only the lat app versions, most of them are incompatible with my device.
    I know that previous versions of these apps were compatible with my ipod.
    Can all download them someway?
    thanks

    The problem is: I never had the compatible versions. But I want them, I'd buy them if I could.
    So I'm stuck with my Ipod, which can't be upgraded anymore to higher IOS versions, and with the appstore, that does not offer older versions; versions that have existed and still exist, perhaps in the recycle bin of some users, or somewhere in the appstore servers.
    I know, its a policy, just to sell more devices. Will not work with me. I'm not buying more Ipods

  • How can I search the last line in an internal table?

    How can I search the last line in an internal table?
    With a describe?? If it is , how can I do that?
    Thanks!!

    Hi shilpa,
    it seems to be you are NEW to SDN. welcome. if you want to get solutions to your Questions, you have to post a NEW thread.dont use the existing thread to post your question.
    any way i am giving you the solution for your question
    LOOP AT ITAB WHERE F1 = <SOME VALUE>
                       F2 = <SOME VALUE>.
    ENDLOOP.
    IF SY-SUBRC = 0.
      ITAB WILL HAVE THE LAST RECORD which satisfying the given criteria in WHERE clause of LOOP.
      write itab <--this ITAB will have the last record.
    ENDIF.
    regards,
    Srikanth.
    Message was edited by: Srikanth Kidambi

  • How can i select the next column instead of next row when press enter key

    I need to know how can i select the next column instead of next row when i press the enter key.By default ,when i press enter key the next row is selected and the column remain unchanged but I wants opposite that is the row should remain unchanged but column index will changed.
    Thanks to all.

    Well, the right arrow key will already move you to the next column, so the easiest way to do this is to modify the InputMap to have the Enter key invoke the same Action as the right arrow key.
    You can search the forum for my "Table Actions" (without the space) example that will show you how to do this.

  • How can I select the existing worksheet while using OLE2 to open the template workboo

    Source:
    application:=ole2.create_obj('Excel.Application');
    workbooks:=ole2.get_obj_property(application,'Workbooks');
    args := ole2.create_arglist;
    ole2.add_arg(args, 'c:\RptTemplate.xlt');
    workbook:=ole2.invoke_obj(workbooks,'Open',args);
    ole2.destroy_arglist(args);
    worksheets:=ole2.get_obj_property(application,'Worksheets');
    args := ole2.create_arglist;
    ole2.add_arg(args, 'Sheet1');      
    worksheet     :=ole2.invoke_obj(worksheets,'Select',args);
    ole2.destroy_arglist(args);
    Problem:
    1. While executing the above code, error -305500 occurs after executing "worksheet := ole2.invoke_obj(worksheets','Select',args)". How can I select the sheet i wanted in the template ??
    2. As I refer to the forms on-line document, it stated that the ole2 programmers documentation can provide all object types and methods that can be used with the OLE2. Does any link can provided to download the specified documentation ??

    The error is probably that your Worksheets variable is actually empty. Looking at your code I think the problem is that you try and get the value of the worksheets collection from the application then you should try and get it from the Workbooks object.

  • When reading an EBook, how can I mark the last page I have read?

    When reading a PDF EBook, how can I mark the last page I have read?

    Hi Pickles 77,
    Sorry to hear you are having issues with your iTunes Store purchase.   The following information should help you with this:
    How to report an issue with your iTunes Store, App Store, Mac App Store, or iBookstore purchase
    To report an issue with your iTunes Store, App Store, Mac App Store, or iBookstore purchase, follow these steps:
    Find the email receipt for your purchase.
    Click Report a Problem under the app that is having the issue.
    When prompted, enter the Apple ID and password you used to purchase the item, then click Report a Problem.
    Click Report a Problem next to the item you are having an issue with.
    From the Choose Problem dropdown menu, choose the appropriate issue.
    Follow the onscreen instructions and—if prompted—type a description of the problem into the text field.
    Click Submit to have your issue reviewed.
    Hope this helps ....
    - Judy

Maybe you are looking for

  • How to do this in a query

    Hello All I have value like these in a table Id Id_num Date 1 PR 10-Jun-2004 1 PF 10-Jun-2005 2 PF 10-Jun-2005 3 PR 10-Jun-2005 Output shoud be 1 PF 10-Jun-2005 2 PF 10-Jun-2005 3 PR 10-Jun-2005 ie. If a ID has ID_NUM values with PF and PR, then PF s

  • Pupose of Item Check in TCode OVA8

    Hai, Can any one tell me the purpose of item check in OVA8. Actually it purpose is to allow credit check at item level.But in my case customer order is blocked only when we check item check in OVA8.Only I want  to know the purpose of it, Regards, Mad

  • Error importing .NEF files

    it is already 1 year since i switch to mac... and now i was re arrange my staff also my photos i have a lot of shots taken with a nikon d50 in .NEF format and modified on PC with a RAW software now if i try to import thos folder i get an error for ea

  • V10.2.0.2 using mapviewer (EA11 and 10.1) to display index MBRs

    I'm new to Spatial and GIS, and trying to confirm that my spatial indexes are ok. I'm trying to view my spatial index mbr along with the geometry in the table using the mapviewer. When I set the SRID to a valid number (4269, 8285) the index mbr is di

  • Call/start function on another package

    hi all, i'm new to java card development.. i'd like to know if it's possible to call/start a function, or assign a value to a variable that belongs in an applet of a different package.. currently, i'm using an old eclipse version for development.. an