+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Junior Member
    Join Date
    Feb 2009
    Posts
    3

    Very basic Javascript question: strings and characters

     
    Hi everyone, I just have a very basic question to ask:

    I have this code (well this is a part of it as you have probably guessed):

    1 char currentCharac;

    2 for (int i = 1; i < myString.length(); i++)
    3 {
    4 currentCharac = myString.charAt(i);
    5 if (!(currentCharac = " " ))
    6 {
    ...

    My problem is that on line 5, my compiler says "incompatible types, found string but expected character" now I get that the " " is the problem because the space is put in as a string, but I have been trying to find out how to declare a space as a character I have found things like \s\ but that leads me nowhere, unless I'm just not doing it right...

    Can anyone help me out?

    Thanks for reading!
    Last edited by flutter; February 25th, 2009 at 01:40 PM.

  2. #2
    ph34r t3h g04t Whir's Avatar
    Join Date
    Oct 2001
    Location
    Kingsford, MI
    Posts
    29,249
    Blog Entries
    7
    Why are you doing it as a character? Just make the variable a string to begin with. Unless it's part of an assignment to use a character?

  3. #3
    Junior Member
    Join Date
    Feb 2009
    Posts
    3
    Thanks for your reply, and yeah it's part of an exercise, but the rules are "just get it to work".
    So I can change it, as always I look for more complicated things than needed!
    Thanks again

  4. #4
    Senior Member
    Join Date
    May 2003
    Location
    Aus, Gold Coast :)
    Posts
    801
    have you declared 'currentCharac'
    "var currentCharac" might help. no promises

  5. #5
    Junior Member
    Join Date
    Oct 2001
    Posts
    27
    shouldn't

    if (!(currentCharac = " " ))

    be

    if (!(currentCharac == " " ))

    or

    if (currentCharac != " " )

    ?

  6. #6
    Junior Member
    Join Date
    Feb 2009
    Posts
    3
    Thank you both for your ideas, but no, there's no need for var, it understands what char currentCharac is (I did try putting var in just incase though )

    And I had tried that myself:
    if (!(currentCharac == " " ))
    or
    if (currentCharac != " " )
    but it still didn't change anything, as I thought before, it is the " " which causes the problem because it is a string and not a character.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Beginner Javascript question
    By James Engle in forum Webmastering and Programming
    Replies: 0
    Last Post: April 21st, 2008, 10:43 PM
  2. Easy (i think) Javascript image swap question...
    By Fade2Grey in forum Graphic Design and Digital Photography
    Replies: 4
    Last Post: April 20th, 2005, 07:05 PM
  3. Quick javascript question
    By NineOne in forum Webmastering and Programming
    Replies: 2
    Last Post: November 5th, 2002, 12:35 AM
  4. WinXP Pro and Javascript question
    By bill1971 in forum Applications and Operating Systems
    Replies: 6
    Last Post: August 31st, 2002, 03:06 AM
  5. dumb javascript question....
    By hawkman2 in forum Webmastering and Programming
    Replies: 8
    Last Post: April 23rd, 2002, 10:18 AM

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews