Get first character from a String

Hi!
I've got a problem with the login of my program:
I want to get the first character out of a String to select two types of users.
eg.
login "a20202" --> a --> first kind of user or
login "b20202" --> b --> second kind of user
Can you please help me?
Bye
Liz

Am I on way to challenge the Worst Code Awards 2004 ? Let me have a go ... It is a far superior code-generating version :)
Kept to ascii-range for the benefit of your monitor (and eyes):class NoMyWayIsFarSuperior {
     public static void main(String[] args){
          System.out.println("public static char getFirstChar(String message){");
          for(int k = 0; k < 256; k++){
               System.out.println("  if(message.charAt(0) == " + k + ") return '" + ( (char) k) + "';");
          System.out.println("  throw new Exception(\"First char not within ascii range ... Please try again.\"); ");
          System.out.println("}");
} The potential for optimisation is endless! :)

Similar Messages

  • Strip the first character from a string

    i am trying to strip the leftmost character from a string
    using the following:
    <cfset Charges.DTL_CHG_AMT_EDIT =
    #Right(Charges.DTL_CHG_AMT_EDIT,Len(Charges.DTL_CHG_AMT_EDIT)-1)#>
    i keep getting the following error:
    Parameter 2 of function Right which is now -1 must be a
    positive integer

    > RemoveChars() much easier than Right()? How so?
    Semantically, if the object of the exercise is to *REMOVE
    CHARacters from a
    string* (which it is, in this case), it is simply better
    coding to use
    removeChars() rather than right(). That, and it's one less
    function call
    (the RIGHT() solution also requires a call to LEN() for it to
    work).
    So removeChars() is "easier" because it reflects the intent
    of the exercise
    directly, is simpler logic, is easier to read, and - I can't
    be arsed
    counting keystrokes - is probably less typing.
    That'd be how.
    Adam

  • How to get specific character from a string

    I have a value such as: 0-5 or 123-30. This is a combination
    from 2 different IDs.
    All I need is to get the number on the right (5 from 0-5 OR
    30 from 123), any number on the right of the "-" character not
    including
    the "-"
    I'm not sure what ColdFusion function can I use safely.
    I said safely since all I can find is either Left or Right
    functions. With these 2 functions, I need to specify the number of
    character to extract while in my case the application is growing so
    the ID may currently be only 1 digit each (0-5) but later it may
    grow longer (123-5677).
    If anyone know the function, please help me. Thank you!

    Something like this?
    Mid(string, Find("-",string)+1 ,
    Len(string)-Find("-",string))
    Since
    Mid(string, start, count)
    and
    Len(string or binary object)
    and
    Find(substring, string [, start ])
    Or perhaps ....
    ListLast(string, "-")
    since
    ListLast(list [, delimiters ])
    Phil

  • The first character in a string

    I need to return the first character of a string, convert it to an integer, and compare it with another integer to see if they're the same. Sounds simple, even for me, but it won't work!!!
    // First question >
    Object userValue1 = JOptionPane.showInputDialog("Blah Blah Blah", JOptionPane.PLAIN_MESSAGE, null, options1, options1[0]);
    Variables.placeholder = (int) userValue1.charAt(0);This is the error I get
    C:\Documents and Settings\imholt\My Documents\OOPAttempt\21_Questions\Engine.java:170: cannot resolve symbol
    symbol : method charAt (int)
    location: class java.lang.Object
              Variables.placeholder = (int) userValue1.charAt(0);
    ^
    1 error
    I have a sneaky suspicion that once I find out what the problem was, I will ask myself why I didn't see it before...

    Try this
    Object userValue1 = JOptionPane.showInputDialog("Blah Blah Blah", JOptionPane.PLAIN_MESSAGE, null, options1, options1[0]);
    String str = userValue1.toString();
    Variables.placeholder = (int) str.charAt(0);

  • How to get first row from View Object cache.

    hi,
    I am using Jdeveloper 11.1.1.6
    can we get first row from View Object cache??
    Thanks in Advance.
    Best
    Shashidhar

    Hi Frank,
    Thanks for reply!!
    My case is:
    I have a Query based ViewObject.
    One of the field is LOV and remaining fields are in ADF table. the LOV field is out side ADF table when i insert first record in ADF table and i choose LOV  filed the value is selected.
    when i create second row LOV value got refreshed because both are in same VO.
    I need to get the LOV value of first row and set same value to second Row.
    Shashidhar

  • How to get each character in a string

    as in 'C' we use arrays to get each character of a string stored in array.how can we get each character of a string stored in a variable.

    Hi,
    For that you need to do offset.
    for example one variable called VAR contains string 'HUMERAH'.
    if you want each character of that string then you need to decalre as many variable as the number of string.
    like
    data : var1(1),
             var2(1),
    var(3),
    var(4).
    var1 = var+(1).
    var2 = var+1(1).
    var3 = var+2(1).
    var4 = var+3(1).
    now var1,var2,var3,var4. contains the single characters.
    Regards,
    Guru
    mark helpful answers

  • Please Help: Ignore first Character in a String.

    How do you ignore the first Character in a String?
    String a = JTable.getValueAt(row,column).toString();
    //Ignore first Char of a? ('$')
    double b = Double.valueOf(a).doubleValue();Any help would be appreciated!

    Ok,so I do that. Now I have the Char '$'. But I don't want '$', I want everything after it. Must I loop throught the rest of the string or can I just remove the first Char?

  • How to get a character from input stream withjout pressing RETURN key?

    In C, we could use getch() form <conio.h> to get a character from the input steam without pressing the return/enter key. How could I tranlate this function for use in Java?

    public static char readChar()
    int charAsInt = -1; //To keep the compiler happy
    try
    charAsInt = System.in.read();
    catch(IOException e)
    System.out.println(e.getMessage());
    System.out.println("Fatal error. Ending Program.");
    System.exit(0);
    return (char)charAsInt;
    }

  • How to get a char from a String Class?

    How to get a char from a String Class?

    Use charAt(int index), like this for example:
    String s = "Java";
    char c = s.charAt(2);
    System.out.println(c);

  • Replace a character from a string

    Hi,
    how can I replace a particular character from a string on a particular occurrence? Say for eg, if i wan to replace 'a' of second occurrence from 'abcabcabc', then what should i do? I guess the normal REPLACE function replaces every occurrence in a given string. So is there any other way to solve this?
    Thanks!

    If you are in 9i:
    Then you got to split the string into based on the nth position.
    SQL> select replace('abddefabc','a','x') from dual;
    REPLACE('
    xbddefxbc
    SQL> select instr('abddefabc','a',2) from dual;
    INSTR('ABDDEFABC','A',2)
                           7
    SQL> select substr('abddefabc',1,instr('abddefabc','a',2)-1),substr('abddefabc',instr('abddefabc','a',2)) from dual;
    SUBSTR SUB
    abddef abc
    SQL> select substr('abddefabc',1,instr('abddefabc','a',2)-1),replace(substr('abddefabc',instr('abddefabc','a',2)),'a','X') as replaced from dual;
    SUBSTR REP
    abddef XbcOfcourse, later on you can join the string..
    Jithendra

  • How to get first Reference from a Mail header?

    One of the fields that may appear in an email message header is "References." I need to get the first item (which is a Message ID) in that field. However, when I try the following script for a message that has one or more IDs in References:
    <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:800px">using terms from application "Mail"
    on perform mail action with messages theMessages
    repeat with eachMessage in theMessages
    set theFirstRef to item 1 of content of header "References" of eachMessage</pre>
    I get: "Mail got an error: Can’t make item 1 of content of header \"References\" of message id 17946 of mailbox \"INBOX\" of account \"David\" into type reference."
    If I omit "item 1 of", I get the complete References field. So I've tried:
    <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:800px"> set theRefs to content of header "References" of eachMessage
    set theFirstRef to item 1 of theRefs</pre>
    but that only gets me the first character (or subsequent characters if I use a value > 1), which is an open-angle. (BTW, I don't understand why breaking the action into 2 steps like this doesn't produce the same error as the first example.) I've also tried:
    <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:800px"> set theRefs to (content of header "References" of eachMessage)
    set theFirstRef to word 2 of theRefs</pre>
    This skips the first open-angle in the References field and gets me all of the string up to the first delimiter. Unfortunately, the number of delimiters that may appear in a Message ID varies, so I can't simply grab a predetermined set and concatenate them. Furthermore, that would remove the delimiters, so the resulting Message ID in theFirstRef would be incorrect.
    I need a syntax that gets me everything between the first set of open- and close-angles but haven't been able to determine what that is.

    Thanks to your pointer, I found "text item delimiters" discussed on pp. 39-40 of the AppleScript Language Guide. A typical References field on my system for the last message in a somewhat long thread looks like this:
    <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]>
    So the message IDs are delimited by spaces and by open- and close-angles. Thus, if I use:
    <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:800px"> set {savedDelims, my text item delimiters} to {my text item delimiters, " "}
    repeat with eachMessage in theMessages
    set theRefs to content of header "References" of eachMessage
    set theFirstRef to text item 1 of theRefs</pre>
    as you suggested, I get "<[email protected]>". That's close to what I want but includes the open and close angles in the returned string. If, however, I specify <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:30px">"<> "</pre> as the delimiters, I get the entire field, i.e., no parsing occurs. I've tried variations and found, for example, that <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:20px">"> "</pre>returns the first string without the close angle, whereas <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:20px">" >"</pre>(i.e., using the opposite order) returns the entire field -- don't understand why the order matters -- but haven't found the magic.
    I know < and > are AppleScript operators (what's more, I've had to take special steps to show the quoted strings properly here) and am wondering whether they're a special case. I've tried using backslash, but that didn't help, either.

  • How to use a regural expression to get all digit from a string.

    Hi All,
    Do you know how to use regural expression to get all digits from the following string via ABAP program?
    "'Log Attributes                 0 (  0 )     (   10 % Available  )"
    Thanks,
    Andrew

    Hi,
    Try the code mentioned below:
      DATA: STR_LEN  LIKE SY-FDPOS,
            RSTR_LEN LIKE SY-FDPOS,
            OFF      LIKE SY-FDPOS.
      DATA: IDX      LIKE SY-FDPOS,        "mn B20K054003
            CL       LIKE SY-FDPOS.        "mn B20K054003
      DATA: RSTRING(40).
      DATA: STRING(40).   " value 'A,N,I,L'.
      FIELD-SYMBOLS: <NLS_CHAR>.           "mn B20K054003
    MOVE I_REGUH-ZNME1 TO STRING.
      MOVE SPACE TO RSTRING.
      STR_LEN = STRLEN( STRING ).
      DESCRIBE FIELD RSTRING LENGTH RSTR_LEN.
      IF RSTR_LEN < STR_LEN. RAISE TOO_SMALL. ENDIF.
      WHILE IDX < STR_LEN.                 "mn B20K054003
        ASSIGN STRING+IDX(*) TO <NLS_CHAR>.   "mn B20K054003
        IF SY-LANGU EQ '2'.                "mn B20K054003
          CALL FUNCTION 'NLS_THAI_CHARLEN' "mn B20K054003
               EXPORTING                   "mn B20K054003
                    THAI_STRING  = <NLS_CHAR>       "mn B20K054003
               CHANGING                    "mn B20K054003
                    THAI_CHARLEN = CL.     "mn B20K054003
        ELSE.                              "mn B20K054003
          CL = CHARLEN( <NLS_CHAR> ).      "mn B20K054003
        ENDIF.                             "mn B20K054003
        IF IDX NE 0.                       "mn B20K054003
          SHIFT RSTRING RIGHT BY CL PLACES."mn B20K054003
        ENDIF.                             "mn B20K054003
        RSTRING+0(CL) = STRING+IDX(CL).    "mn B20K054003
        IDX = IDX + CL.                    "mn B20K054003
      ENDWHILE.                            "mn B20K054003
    Regds,
    Anil
    Edited by: Matt on Jul 1, 2009 9:36 AM -added code tags

  • Getting char values from a string problem

    Hi,
    Here's an example of what I'm trying to do:
    boolean loopSwitch = true;
    while (loopSwitch)
         String orderDecider = JOptionPane.showInputDialog (null, "Would you like your numbers to be ordered in   ascending or descending order(A/D)",      "Order decision", JOptionPane.QUESTION_MESSAGE);
         if (orderDecider == A)
         loopSwitch = false;
         }I basically want the user to input either a/A/d/D and to get the char values from the string so I can use them in an if statement.
    Basically, I wanna parse the string into a char.
    Is this possible?
    Thanks.
    Edited by: xcd on Oct 16, 2009 8:38 AM

    Why not just use the String.equals() method to compare a String to a String?
    But if you must, you can use the String.charAt() method to return a char at a particular location in the String.
    Note: char literals need to be surrounded by single quotes ('A') and String literals need to be surrounded by double quotes ("A").

  • Formula for getting first letter of the string

    Post Author: jmmj
    CA Forum: Formula
    Hi, I have a problem to get the first letter of the string.  I need to compare first letter first and then change the rest of string to number as unit cost for calculation.  For example, I have string K100, C200,...     if first letter = K then 0 else if first letter = C then tonumber200..... I use CRXI, any assistance will be appreciate.jmmj 

    Post Author: jmmj
    CA Forum: Formula
    It works, thanks Kai!But when I tried to print the report, there are multiple lines shown same invoice number but different unit price. My formular is: IF {OEINPR3.COINTYPE} = 2 OR CCur({OEINPR3.LINETYPE}) = 1  //line type 1 for item,  2 for misc. charge THEN(    IF {OEINPR3.COIN}&#91;1&#93; = "K" OR {OEINPR3.COIN}&#91;1&#93; = "N"  THEN        TONUMBER(MID({OEINPR3.COIN},2,20))    ELSE 0)ELSE      2 //for testing only The result I have: Line#    Inv#    unitprice    total1          IN001    0.00     10.00            IN001   10.00     10.00  2          IN002    0.00     20.00             IN002    20.00     20.00.......The second line of each invoice is correct. How can I print just one line for each invoice which is correct? Thanks!jmmj  

  • Picking character from a string

    Hi guys
    How to pick each character of a string containing few character without using a loop. Like "LabVIEW" will become a array of string "L","a","b" etc
    Thanks in advance
    Niladri

    Why would you not want to use a loop?
    You could use String Subset in a loop to get each byte.
    You could alsoe use String to U8 array to get an array of bytes.  Then convert that back to individual string characters by using the typecast function in a loop with autoindexing turned on.
    Attachments:
    Example_VI_BD.png ‏10 KB

Maybe you are looking for

  • HT1711 Sub-titled movies in iTunes

    I viewed the trailer for a movie in iTunes which had sub-titles.  When I downloaded it to my Apple TV there were no sub-titles.

  • Is DHCP really necessary?

    HI, I have a WRT54GS Wireless router is a small (4 system) office. We recently had one system go down and lost power to the cable modem and the router around the same time.  When we brought the systems back up, we discovered that the router had done

  • PS crashed... can't open psd file

    Hey, My PS Crashed while working on a project and PS doesn't want to open the file again... I tried a few things like copie&past in an other folder and to rename it but al of these things doesn't work... I tried to open the file with Irfanview but th

  • Java.util.concurrency.Lock versus synchronized()

    Which method is more efficient? or are they both equally efficient for different uses? Thanks, Gili

  • SharePoint 2013 My Site Cleanup Timer Job

    Is the My Site Cleanup Timer Job responsible for deleting the User Profile or just the Mysite or both? Are Profiles deleted after 14 days or is it some other number. Is there any action that would extend this time frame I am not able to find any 2013