String Character Selection

I just want to know if anyone knows the code so I can select the first character in a string and the last character in the string so that I can do the following function :
First("ABC") ^ Last("ABC") = Answer
Tks for any help

You can use the charAt() method of the String class to help you find out the values. To find the first character use charAt(0) and to find the last character you can use charAt(String.lenght() - 1).
Example:
String word = "ABC";
char firstLetter = word.charAt(0);
char lastLetter = word.charAt(word.length() - 1);
I hope this helps.

Similar Messages

  • How do I make a "Character Select" system?

    I'm making a game for school that is a vertical scrolling shooter (like the Raiden series), based off of the anime Galaxy Angel. For anyone who has seen GA would know there's 5 main characters, all of which I have put in my game. My program is an application (so swing answers only please), and made up of 4 classes: Title Page, Character Select, Main Game, and Credits. I intend to make my program load different Player sprites depending on what character is chosen. Can someone tell me how I can make my Main Game class read which character has been chosen from my Character Select class?

    A very quick and easy way of doing this with Swing is using the JRadioButton class. The following suggestion is similar to a technique used in "How to use Radio Buttons".
    http://java.sun.com/docs/books/tutorial/uiswing/components/button.html#radiobutton
    Inside CharSel class:
    First, declare a class String variable called "userIcon" or something at the top of your program. This will be the path of the icon for your user.
    private static String userIcon=null;When you're setting up the GUI for your CharSel screen, use an array of JRadioButtons for the character buttons. In the for loop where you initialize each button, group them all, and set up the basics (ie: stylize the button to make it feel more like a game), add something like this:
    buttons.addActionListener(this); //assuming you've implemented ActionListener
    buttons[i].setActionCommand("images/charIcon"+i+".gif");
    The i variable is just an int; the current index of your radio button array in your for loop. An action command is simply a String passed to the ActionEvent of your ActionListener.
    You would then add something like the following so you can retrieve the icon's path from other classes:
    public static void setUserIconPath(String s) { this.userIcon = userIcon; }
    public static String getUserIconPath() { return userIcon; }
    //called when a radio button is pressed
    public void actionPerformed(ActionEvent e) {
      //retrieve the action command
      setUserIconPath(e.getActionCommand());
    }When you are writing your actual game classes, you'll create the user image using the static methods:
    ImageIcon portrait = new ImageIcon(CharSel.getUserIconPath());If you wish to avoid the static methods (which may cause problems depending on how you use them), you can set the constructor of your MainGame class to accept the icon's path (or just the ImageIcon itself).
    Alternately, you could simply call a method passing the path/imageicon [i]after you initialize your MainGame class.
    Other techniques may include constant ints and a switch statement (which checks something like CharSel.selectedIcon() == CharSel.BOB). Of course, a more typesafe way of doing that would be to use enums. If you did use enums, you could even include methods for your enum constants (ie: CharSel.Chars.BOB.getImageIcon() may return Bob's ImageIcon).
    Good luck!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Xml data considered than strings character in«append»&«insert-aft»operation

    Hello,
    I use BPEL10.1.3.1. Here is my problem. I recuperate in a database a CLOB data type :
    <c>
    <d>
    <e></e>…
    </d>
    <f>
    <g></g>
    <h></h>…
    </f>
    </c>
    I insert this CLOB data type in a new variable "compteRenduXml" (type : simple type, xsd language). When I visualize my "compteRenduXml" variable, it is a xml data (that's OK).
    I am trying to insert the "compteRenduXml" variable after the <b>…</b> operation :
    <a>
    <b>…</b>
    </a>     
    The problem is the variable I would like to insert is considered than strings character (and not xml data ! ).
    After, when I try to insert a value in "<e>abcd</e>" for example, I have this error : « The XPath chain does not return any node. »
    Can you help me ?
    Thank you.
    Tania

    If in my Sqlloader script I use :
    INTO TABLE XML_DOCUMENT_TABLE_VWO TRUNCATE
    XMLType(xmlcol)
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
    xmlcol
    I have always this error whith the two XML document (< 255 kb, & > 255 Kb)
    Table XML_DOCUMENT_TABLE_VWO, loaded from every logical record.
    Insert option in effect for this table: TRUNCATE
    Column Name Position Len Term Encl Datatype
    XMLCOL FIRST * , O(") CHARACTER
    Record 1: Rejected - Error on table XML_DOCUMENT_TABLE_VWO.
    ORA-00904: "SYS_NC_ROWINFO$": invalid identifier

  • Finding strings in "Selected Files in Site" not working

    When searching files for a string, and selecting "Selected Files in Site", Dreamweaver (starting today) will only search the root directory, NOT the selected subdirectory.  This is uselss.  I've been using Dreamweaver for years.  Today I switched to mapping the site with an IP address instead of a server/domain name, could this be the culprit?

    I encountered exactly the same problem.
    I'm trying to solve this problem...

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

  • String str = " Select ? , ...

    Hi ,
    I have a query for which I need to use PreparedStatement .The query runs likes this :-
    String str = " Select ? , ename from emp where deptno ? ";
    The values of ? need to be assigned dynamically.
    But I cannot create Prepared Statement from this query .
    If you have got answer to your questions can you inform me at
    Thanks in advance

    No, and you can't use a PreparedStatement where you have ? for the table name either. The database can't prepare it because it doesn't know what fields you will be asking for. So you will have to use a Statement and generate the SQL with string calculations. Sorry.

  • String in Select option

    Hi experts,
    I want to get a string length of greather than 100 through select options / Parameter .  Is it possible...? then how..?
    Pls give me a solution.
    Regards,
    Murugan arumugam.

    Hi..
    PARAMETERS : p1 type string.
    SSTRING 1-255 Character string string
    STRING 256-... Character string string
    The type SSTRING is available as of release 6.10 and it has a variable length. Its maximum length must be specified and is limited to 255. The advantage of this type compared with CHAR, is that it is assigned to the ABAP type string.
    <b>Reward points for useful ans..</b>
    Thanks & Regards
    ilesh 24x7

  • How to read a string character by character and pass it into an array

    Hi,
    I have a requirement to write a function.The thing is,i need to read string,replace space with a NULL,return in the form of an arrayy.
    for this what i thought is,if the character is not a space,i need to put that into array,if its space,put a NULL for that.
    the string is of type varchar2.
    ex:XX XX XX
    i need some suggestions for this.
    thanks

    Well, you can just use a loop that runs for the length of the string.
    Then for each iteration of the loop, take the next character of the string (substr or similar) and add it to the array. If it's a space, then add a NULL to the array (if that's what you want).
    Easy :)

  • Open cursor for string and select from partition (cannot bind)

    Hi,
    i don't manage to use a bind variable for a select ... from ... PARTITION(...).
    It doesn't work to use something like
    open cur for 'select ... from ... PARTITION(:1) where ...' using 'NDAY_20120301';So i have to create the cursor string with string functions each time i change the partition.
    But that means, that the string changes each time.
    Doesn't that prevent from re-use in library_cache?
    best regards,
    Frank

    >
    So i have to create the cursor string with string functions each time i change the partition.
    But that means, that the string changes each time.
    >
    Yes it does.
    Doesn't that prevent from re-use in library_cache?
    >
    Yes it does.
    So why do you care? Unless you have large numbers of partitions what difference does it make? Bind variables are useful to keep Oracle from doing hard parses of queries that are basically the same but use different filter values. Such as an INSERT statement that uses different values FOR EACH ROW rather
    You are just constructing the main (non-filter) part of the query one time and need a single value for the entire query regardless of how many rows - that isn't really a use case for bind variables and isn't going to provide any real benefit.
    So the real question is why do you even care about something that wouldn't provide any benefit to you even if you could do it?
    Looks like you just want to 'roll your own' parallel processing rather that use, and pay for, Oracle's parallel functionality.
    If each partition uses its own tablespace you could filter on the FILE Id of the ROWIDs since the file number will be different for each tablespace and datafile.
    1. Determine the list of file numbers for each partitions tablespace.
    2. Use a WHERE DBMS_ROWID.ROWID_RELATIVE_FNO (ROWID) = :n filter (or use IN (:n1, :n2))to filter rows based on file number(s) for the partition you want
    See DBMS_ROWID.ROWID_RELATIVE_FNO in the PL/SQL Packages and Types doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_rowid.htm#i1004259

  • 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

  • String character conversion

    Can anyone explain me why there are 5 characters in the first range of 256 that are coded back to the question mark.
    for (int i = 0; i < 256; i ++)
         byte[] bytes = new byte[1];
         bytes[0] = (byte) i;
         String temp = new String(bytes);
         byte[] result = temp.getBytes();
         if (result[0] != bytes[0])
              System.out.println(i + ") byte->" + bytes[0] + "< result->" + result[0] + "<");
    }characters 129 (reserved), 141 (RI), 143 (SS3), 144 (DCS) and 157 (OSC) are changed. I m using JDK 1.4.2_02.
    I'm posting it here because I stumbled on it when I was trying to convert a string (known to me as UTF-8) to a Java UTF-8 String. The Greek lower RHO character is '0xCF 0x81' and that last one is 129.

    Rather than crossing your fingers and hoping for the right encoding, you should provide the encoding you wish to transcode explicitly. Here, I test US-ASCII and ISO-8859-1. US-ASCII complains for all code points above 127 (as expected; it's a 7-bit encoding), whereas ISO-8859-1 runs without complaining.
    public class TestEncoding {
      public static void main(String[] args) throws Exception {
        String[] encodings = new String[] {
          "US-ASCII", "ISO-8859-1"
        for (int i = 0; i < encodings.length; i++) {
          System.out.println("TESTING ENCODING: " + encodings);
    testEncoding(encodings[i]);
    public static void testEncoding(String encodingName) throws Exception {
    for (int i = 0; i < 256; i ++) {
    byte[] bytes = new byte[1];
    bytes[0] = (byte) i;
    String temp = new String(bytes, encodingName);
    byte[] result = temp.getBytes(encodingName);
    if (result[0] != bytes[0]) {
    System.out.println(i + ") byte->" + bytes[0] + "< result->" + result[0] + "<");

  • String length excluding input string/character

    Long story short, I want to replicate the String Length function but to not include an input string in the character count. For example:
    The input (search) string is "the".
    My first string to test is "The big red dog."
    This would return a string length of 13.
    My second string is "Jumps over the lazy fox."
    This would return a length of 21.
    "Hello World!" would return 12.
    "The Lion The Witch And The Wardrobe" would return 26.
    Hopefully you can see what I'm trying to achieve. How is this possble?
    - James
    (I am runnnig Labview 8.5)
    Never say "Oops." Always say "Ah, interesting!"
    Solved!
    Go to Solution.

    Use the Search and Replace String to replace your "exclusion string" with an empty string.  Use the String Length on the resulting string.  Make sure the Relace All is set to TRUE.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    String Length.png ‏11 KB

  • String Character

    Hi Guru,
               Please tell me how we can read exactly second character in string.
               Suppose my string is "ABAP". i want only B. Please guide me....
               Thanks in advance.
    Best Regards,
    Vinayak.

    Breakpoint,
    What does the code segment have to do with *STRING*?
    The code snippet in my thread is using offset. Hope that's fine.
    DATA : var(20) TYPE c VALUE 'ABAP',
           v_offset TYPE c.
           v_offset = var+1(4).
           WRITE : v_offset
    Regarding the FM its also helps to split the string at a given postion as per user's
    choice. In OP case he wants 'B' to be picked up from 'ABAP'. I.e. Second
    letter of every entered string or any combination of characters.
    May be you would like to test this code.
    DATA: E_HEAD(2) TYPE C,
          E_TAIL(2) TYPE C.
    CALL FUNCTION 'C147_STRING_SPLIT_AT_POSITION'
      EXPORTING
        i_string         = 'ABAP'
        i_position       = '2'
    IMPORTING
       E_HEAD           =  E_HEAD
       E_TAIL           =  E_TAIL.
      E_HEAD = E_HEAD+1(1).
    WRITE : E_HEAD
    Edited by: Mishra.Manas on May 10, 2010 1:53 PM

  • Making space for string (character) in Java

    A permutation is a function. In this particulate exercise, the function is certain space separation of an adjacent letter. Here is an example for the space is 2: After the first letter A, skip 2 spaces and arrive at D, skip another 2 space to arrive at G, so original ABC maps to adg.
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    maps to (with skip of 2 space):
    adgjmpsvybehknqtwzcfilorux
    You need to have a user input for the skip space, similar to the lab 1. Warning: Because there are 26 characters in the English alphabetic, if user enters an even number, you need to consider add one every time it passes the Z letter. Please help me to solve this problem.

    Try using this code segment:
    String abcString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    StringBuffer tempBuffer = new StringBuffer();
    StringBuffer outBuffer = new StringBuffer();
    tempBuffer.append(abcString);
    i = 0;
    while(i < abcString.length())
    outBuffer.append(tempBuffer.charAt(i));
    i+=2;
    tempBuffer.setLength(0);
    All you really need to do is change what you're adding to I every time you go through the loop, make it user input. This is simply an example of how to do it.
    -Jason Thomas.

Maybe you are looking for

  • HOW TO - Create new from clipboard and process multiple files - please help

    Need help - have new version of photoshop on trial only ATM... Want to know - HOW TO: 1. Create new from clipbaord 2. Process multiple files Please help.

  • Importing of Data

    Can anyone tell me that is it possible to import data from a text file as we can import in access without converting it to script or is there any utility to do so? Your help will be highly appreciated! Thanx........ Muhammad Umair

  • Returns for Stock Transport Order / NB PO

    Hello Friends, I have a scenario where the we have 2 Inter company entities doing purchasing scenario. The document flow is - Uk raising a NB PO to NL>UK does a Outbound Delivery>NL does an Inbound Delivery-->and then UK raises a Inter Company Invoic

  • By default In a table Data should be Displayed.before clicking the search b

    Hi All, I m using adf11g.I have taken adf query with panel(thrgh Drag&drop in named Criteria).after that i have taken table(Drag Drop in a form ) from Data Control. So My Requirement is By default In a table Data should be Displayed.after that clicki

  • SPA 514G stuck SOS etc etc unable to recover

    I have two SPA414G IP Phones with screen displaying "S.O.S. – Phone In Recovery Mode" I did follow the procedure to recover SPA514G without any success. I did notice on the Configuration Upgrade that Software Version is 7.5.1tec. (see attached pictur