+ 1
Can someone please tell me what's wrong with my code? It's doing weird things.
8 Answers
+ 1
I'd like it to write the words individually without spaces (or underscore in this case), like this:
hello
world
so
what
But there are errors at the end that I can't explain. Sorry, the extra messages and underscores were for testing and debugging.
+ 1
Yes, the redundancy is because I thought the variables some how weren't updating and I forgot to change it back. The IndexOf only has one attribute because I heard that default was the end of the string.
But I guess I don't have to explain myself if it's wrong. How do I "contain" a string?
+ 1
Sorry I had trouble reading you code.
Determining whether something was extra debugging or a intended sequence.
So I wrote my own code.
First of all now everything passes the same lines
Have a look and let me know if this meets the requirements.
Do not copy the code.
Read it and understand what it is doing.
I Squeeze everthing in one method
https://code.sololearn.com/cfqGrrZ3W6u4
+ 1
Wow, that's exactly what I wanted and very poetic I might add. And no, I'm not in school. I just didn't know about that, I'm still learning : ) thank you
p.s. I like your name
0
What is going wrong ?
if I put in "hello world"
the output is "hello world"
if I put in "hello_world_so_what"
I get a lot of writeline, that have a almost correct output
But I do not know what to expect
Can you tell me what you expect in the sentence
"hello_world_so_what"
0
There are a lot of redundant lines that try do the same, but fail because they are slightly different.
First explain substring and indexof
https://www.dotnetperls.com/substring
Substring
Use the Substring method with start and length ints
So substring uses startposition and length of the string
Indexof
https://www.dotnetperls.com/indexof
Call the IndexOf method. IndexOf returns the first index of specified character or substring.
Hello_
012345
//start counting at zero
//give position including the character it self
So to print "hello"
do
int s = text.IndexOf("_");
string w = text.Substring(0,s);
to be continued
0
At first, you use .substring with only one attribute , this causes errors, at second indexOf returns something weird(propably -1) if the string you search for isnt contained, that means that you use this weird value to get the next substring so you again run into an error.
0
Additional comment.
I am not sure if you are allowed or you are doing school work and it is not allowed.
Have a look at split
https://www.dotnetperls.com/split