+ 1

Can someone please tell me what's wrong with my code? It's doing weird things.

https://code.sololearn.com/c7xq6wSN420p/?ref=app

9th Oct 2019, 7:39 PM
Ghostfly
Ghostfly - avatar
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.
9th Oct 2019, 8:31 PM
Ghostfly
Ghostfly - avatar
+ 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?
9th Oct 2019, 9:26 PM
Ghostfly
Ghostfly - avatar
+ 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
9th Oct 2019, 9:39 PM
sneeze
sneeze - avatar
+ 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
9th Oct 2019, 9:56 PM
Ghostfly
Ghostfly - avatar
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"
9th Oct 2019, 8:23 PM
sneeze
sneeze - avatar
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
9th Oct 2019, 9:09 PM
sneeze
sneeze - avatar
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.
9th Oct 2019, 9:09 PM
Lord HN
Lord HN - avatar
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
9th Oct 2019, 9:46 PM
sneeze
sneeze - avatar