• Post Reply Bookmark Topic Watch Topic
  • New Topic

Null-String  RSS feed

 
Paul Horner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys and girls,
I have a realy digusting problem, which I can't solve.
I want to set a String in a String Array with Chars like this:

but when I want to get the testString, I get this as an answer:
input:
top
output:
nulltop

how can I fix this?
Greetings, paul
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Did you initialize the resultant string to start with a blank string?

Henry
 
Liutauras Vilda
Sheriff
Posts: 4914
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul Horner,

I have formatted and indented your code, so everyone could read it. I hope you don't mind.
Also, I changed "nothing" to an empty statement ";" and "nothing" left as a comment, so other people could understand that your intention is to do nothing in "if" body.

Welcome to CodeRanch.
 
Kendall Ponder
Ranch Hand
Posts: 205
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put your code in a class called Temp so you could see if I am understanding your question correctly. I ran the following code:

This gives me an output of: nulltopbottom

If you change line 2 from

to
you get an output of: topbottom which is what I think you want and I think that is what Henry was referring to.

You might want to consider writing a separate method for the test as follows. It gets rid of your do-nothing branch. I think naming the test makes it easier to understand what you are trying to accomplish (I learned that on this forum).


 
Paul Horner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I got it and the solved the problem earlier. Now I have just other problems, which you cannot solv and which are not for this thread ;)
lg Paul
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!