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

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

  • Replace the first character in a String with blank

    String a = dgramRsp.getAddress().toString();
    a = a.replace('/','');The problem with the first statement is that it returns an ip address with a '/' in front of it. Like so.../192.168.0.190
    I need to get rid of the '/'. The replace won't work because it wants a character between the ' '. Thanks for your time.

    I had to think about it for a sec but yes you're
    right.
    InetAddress a = dgramRsp.getAddress();
    String b = a.getHostAddress();
    substring(1) would have worked, too, but it would have been redundant (removing a previously added slash).

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

  • TestStand database logging problem: only the first character is put in the table.

    I am using TestStand 2.0.1 and Microsoft SQL server database. There is a weird problem when I use database logging. At first, all the database logging ran good.
    Then one day after I moved the test equipment to production line, TestStand only logs the first character of each string field in the tables! There is no error message.
    I setup another SQL server running locally on the same machine as the TestStand is and move the database to the local server, database logging has no problem. Schemas in TestStand Dabasebase Options are the same.
    I tried to run TestStand from another computer on the network. There was no problem before, too.  But now, TestStand always shows a Run-time error message like this:
    Details:
    An exception occurred calling 'LogResults' in 'ITSDBLog' of 'DBLog 1.0 Type Library'
    An error occurred executing a statement.
    Schema: New.
    Statement: STEP_RESULT.
    Connection failureMultiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
    Source: TSDBLog
    Error Code:
    -2147467259; User-defined error code.
    Location:
    Step 'Log Results to Database' of sequence 'Log To Database' in 'Database.seq'
    I have checked that the connection is good and also the table UUT_RESULT has been logged correctly.
    Anyone can help?
    Thanks.

    Thank you very much, Santiago.
    Yes, I have a customized schema, but it is based on the pre-existing schema. I tried the schema:TS 1.x Access/SQL (NI), which  came with TestStand, the results were the same. 
    I have tried to run different sequences. On one computer, I always get only the first character of each string entry logged in the remote database, however for the local server, everything is fine. On the other computer, there is no local SQL server, I always get similar error message as I mentioned in my post. The sequence step reports error is  "Log Results to Database".
    Any more suggestion?
    Thanks again.
    Best regards,
    Jaso

  • Only display the first character issue

    Hi,
    I'm using CR 2008 to generate reports.
    I use oracle database.
    I use a stored procedure to get data and everything working fine ,it return correct data.
    I have five details section but i display one details section and i suppress others
    My issue is execute the rpt file to presssig F5 key;   string type record is only able to print the first character on the preview.
    eg: record with value 'ABCDE', after printed on rpt file, only character 'A' was printed on the preview.
    if i verify database, it display correct data but a few times later problem occurs again
    Anyone know how to fix it?

    if you create a blank report as follows , you will take same error
    my reports section;
    section - formula fieds 
    a - - - - a b f g
    b - - - - a b e f g
    c - - - - a b c e f g
    d - - - - c f g
    e - - - - d e f g
    my details sections suppress formula;
    if {CR_TEST.CODE}=1 then false else true
    if {CR_TEST.CODE}=2 then false else true
    if {CR_TEST.CODE}=3then false else true
    if {CR_TEST.CODE}=4 then false else true
    if {CR_TEST.CODE}=5 then false else true
    my procedure is just like this;
    CREATE OR REPLACE PROCEDURE CR_TEST(
       P_MONTH IN VARCHAR2
    , P_YEAR IN VARCHAR2
    , CODE IN NUMBER
    , P_CURSOR OUT GP.REF_CURSOR
    IS
    BEGIN
       IF CODE = 1
       THEN
          OPEN P_CURSOR FOR
             SELECT A
                  , B
                  , 'X' C
                  , 'X' D
                  , 'X' E
                  , F
                  , G
                  , CODE CODE
               FROM CR_TEST_TABLE
                                 --WHERE conditions
       ELSIF CODE = 2
       THEN
          --A, B, E, F, G
          OPEN P_CURSOR FOR
             SELECT A
                  , B
                  , 'X' C
                  , 'X' D
                  , E
                  , F
                  , G
                  , CODE CODE
               FROM CR_TEST_TABLE
                                 --WHERE conditions
       ELSIF CODE = 3
       THEN
          OPEN P_CURSOR FOR
             SELECT A
                  , B
                  , C
                  , 'X' D
                  , E
                  , F
                  , G
                  , CODE CODE
               FROM CR_TEST_TABLE
                                 --WHERE conditions
       ELSIF CODE = 4
       THEN
          OPEN P_CURSOR FOR
             SELECT 'X' A
                  , 'X' B
                  , C
                  , 'X' D
                  , 'X' E
                  , F
                  , G
                  , CODE CODE
               FROM CR_TEST_TABLE
                                 --WHERE conditions
       ELSIF CODE = 5
       THEN
          OPEN P_CURSOR FOR
             SELECT 'X' A
                  , 'X' B
                  , 'X' C
                  , D
                  , E
                  , F
                  , G
                  , CODE CODE
               FROM CR_TEST_TABLE
                                 --WHERE conditions
       END IF;
    END;
    Edited by: assaulter on Oct 12, 2011 11:50 AM
    Edited by: assaulter on Oct 19, 2011 1:50 PM

  • Even more about deleting the first word in a string

    hi, i have this code that removes the first word in a string, returns the shorter string, removes the first word from the shorter string aso... what i would like it to do is to stop when it hits a non-character, but i can't get it to do that. does anyone know why \b won't work?
    import java.io.*;
    class Testar {
    public static void main(String[] args) {
          String partDesc = "Hi my name is SandraPandra.";
          while (partDesc.equals("\b") == false) {  //this is where something goes wrong
              System.out.println(partDesc);
              partDesc = partDesc.replaceFirst("^(\\w+)\\s+","");
    } thanx in advance!

      while (partDesc.equals("\b") == false) That compares partDesc to a string consisting of one backspace character. I suspect you're trying to use the regex word-boundary anchor, but that's a dead end. If you want to stop beheading the string when the regex stops matching, you can write the code exactly that way: class Testar {
      public static void main(String[] args) {
        String partDesc = "Hi my name is SandraPandra.";
        while ( partDesc.matches("^(\\w+)\\s+.*") ) {
          partDesc = partDesc.replaceFirst("^(\\w+)\\s+","");
          System.out.println(partDesc);
    } If performance is a concern, you can use a pre-compiled Pattern object for greater efficiency. Thanks to Matcher's lookingAt() method, you can use the same regex for the test and the replacement: class Testar {
      public static void main(String[] args) {
        String partDesc = "Hi my name is SandraPandra.";
        Pattern p = Pattern p = Pattern.compile("^(\\w+)\\s+");
        Matcher m = p.matcher(partDesc);
        while ( m.lookingAt() ) {
          partDesc = m.replaceFirst("");
          System.out.println(partDesc);
          m.reset(partDesc);
    } The ^ anchor isn't really necessary in this version, since lookingAt() implicitly anchors the match to the beginning of the string, but you might as well leave it in.

  • 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! :)

  • [CS2/CS3 JS] Finding the first character of each paragraph

    Hi,
    Can anybody help with my script below:
    for (h=0; myParaCount>h; h++){
    myChars = myStory.paragraphs.item(h).contents;
    if (myChars.characters.item(0) == "l" && myChars.characters.item(0).appliedCharacterStyle == CharStyleWin){
    myStory.paragraphs.item(h).appliedParagraphStyle = "L-B";
    This script is supposed to test if the first character is an "l" with my character style "Wingdings" applied to it. I could not test whether the character style is "Wingdings" or not. What could be wrong with my script. Thanks.

    // You need to have a textFrame selected
    var myFrame = app.selection[0];
    var myParaCount = myFrame.paragraphs.length;
    // There must exist a paragraphStyle name L-B
    var myApplyStyle = app.activeDocument.paragraphStyles.item("L-B")
    for (h=0; h < myParaCount; h++){
    var myChar = myFrame.paragraphs.item(h).characters.firstItem();
    // check if first char is "l" and if its applied charstyle name is CharStyleWin
    if (myChar.contents == "l" && myChar.appliedCharacterStyle.name == "CharStyleWin"){
    myFrame.paragraphs.item(h).appliedParagraphStyle = myApplyStyle;
    /* Edited at 11.21 */

  • Delay when typing in Safari, the first character is always missing.

    Recently when I go to type in a address or text in the search window, the first first character is always gone. Resulting in me having to back space to the beginning to re-type the first character.
    My father is a Mac user too and he experiences the same thing.
    Any suggestions?

    Hi,
    The problem you described sounds reminiscent of a problem many MacBook, MacBook Pro and even PowerBook G4 users have been experiencing. If you do a Discussions-wide search for the phrase "first key" in quotation marks, you'll get an idea of how wide-spread the problem is. Apple recently released a firmware update for the MacBook and MacBook Pros, but reports of first-key-unrecognition persists.
    While I hope your problem isn't of this variety, the point I'm trying to illustrate is that if it is, Apple has yet to pin down a proper fix for it. Until they do though, perhaps some workarounds you can try are banging on a modifier key before typing anything, or clicking twice to ensure focus has been given to a window element and not just the window.
    Yang

  • Getting zero to display as the first character

    I know this should be simple, but I'm trying to get a zero to display as the first character in a field when necessary.  For example last 4 of SSN.  Any help would be appreciated.

    Hi,
    You can achieve this in the Patterns dialog. Select the object and go to the Object > Field palette. There you can click the Patterns button and edit the Display Pattern.
    For example, this would display a number without leading zeros: 12
    num{zzz9}
    Whereas if you use 9 it will display leading zeros: 0012
    num{9999}
    Hope that helps,
    Niall

  • How can a  variable display the first character that's on the page?

    I'm creating a telephone directory and want each page to display the alphabet of the first listing on the page on the top - only one character.
    Can you tell me how to do this?

    Hmmmmm, seems I was wrong about the GREP styles. I just tried it and they don't get picked up. I consider that a bug, but it's probably "as designed."
    That leaves you having to work with nested styles only, or Find/Change. I think what you'll need to do is redefine the Paragraph style so it has two nested styles that apply the correct style to whatever needs to be styled at the start of the paragraph, one for the first character and the second for the rest of the word(s) if you can figure out a trigger (can InData add an end nested style character or is thew some punctuation you can use?), then find/change to remove the applied character style. For that I'd serach for ^.+ with the find format set to the character style that InData applied and the chane format set to [None], which will only remove it from the beginning of your paragraphs. If this is done correctly there will be no change in appearance since the redefined paragraph style will do the formatting.
    If that won't work, you can use find/change to apply a new style to the first characters. Search for ^. and set the change format to the new character style that you'll use in the variable. It needs to have the same attributes as the style applied by InData or the appearance will change.
    The second method is probably easier since you don't need to redfine the paragraph style, but both methods require you to use find/change to alter the text, which means if more text is added you'll need to re-do the find/change. Not a big deal, but don't forget. I'd be tempted to wait until the last minute and just ignore the headers for the moment, if editing is ongoing. I'd also test this on a copy of the file for safety.

  • How can I stop when the first character I type into start page search matches my thunderbird password the whole password is revealed.

    Typing into the Mozilla start page my thunderbird/gmail password is revealed as a suggestion pop-up when the first character is typed.

    See:
    * http://kb.mozillazine.org/Deleting_autocomplete_entries

  • Safari cannot open the page because the first character is invalid, how can I fix?

    I cannot open PDF's.  Error message appears saying, Safari cannot open the specified webpage because the first character is unrecognizable".  What do I need to do to fix it?

    Hi..
    Go to   /Library/Internet Plug-Ins
    Move the Adobe PDF browser plugin  (or PDF browser plugin) to the Trash.
    Quit then relaunch Safari.

  • How we can find the last character in a string(Urgent Plz!)

    Gurus!
    How we can find the last character in a string.
    e.g i have a string say "Str" with value "10-01".
    Now i want to find the last character in "Str" i.e "ONE=1".
    i am using Oracle developer 6i with Oracle 8i(1.7).
    Plz help!
    Many thanks!

    Use the substr() and length() functions -
    x := '10-01';
    y := substr(x, length(x));

Maybe you are looking for