Thread: Very basic Javascript question
-
February 25th, 2009, 01:19 PM #1Junior 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.
-
February 25th, 2009, 01:52 PM #2
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?
-
February 25th, 2009, 02:07 PM #3Junior 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
-
February 26th, 2009, 06:26 PM #4
have you declared 'currentCharac'
"var currentCharac" might help. no promises
-
February 26th, 2009, 08:47 PM #5Junior Member
- Join Date
- Oct 2001
- Posts
- 27
shouldn't
if (!(currentCharac = " " ))
be
if (!(currentCharac == " " ))
or
if (currentCharac != " " )
?
-
February 27th, 2009, 11:36 AM #6Junior 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
-
Beginner Javascript question
By James Engle in forum Webmastering and ProgrammingReplies: 0Last Post: April 21st, 2008, 10:43 PM -
Easy (i think) Javascript image swap question...
By Fade2Grey in forum Graphic Design and Digital PhotographyReplies: 4Last Post: April 20th, 2005, 07:05 PM -
Quick javascript question
By NineOne in forum Webmastering and ProgrammingReplies: 2Last Post: November 5th, 2002, 12:35 AM -
WinXP Pro and Javascript question
By bill1971 in forum Applications and Operating SystemsReplies: 6Last Post: August 31st, 2002, 03:06 AM -
dumb javascript question....
By hawkman2 in forum Webmastering and ProgrammingReplies: 8Last Post: April 23rd, 2002, 10:18 AM



LinkBack URL
About LinkBacks



Reply With Quote

It was nice to see you too! Your son is a hoot! :) Too bad it wasn't under better circumstances.... :(
Is It Just Me? v233893843