Oli R.
I am new to c# and need help
You can also do user Input.IndexOf('-') or user Input.LastIndexOf('-') to see if and where there is a '-' inside the user-input-string. But the easiest way would be to iterate over the user-input-string with a for-loop to check if the actual character is a "-".
excample: for( int i = 0; i < userInput.Length; i++) { ... }
38 replies
I am new to c# and need help
Well, in my opinion, it can be very difficult for a beginner to come up with good English names for the identifiers in addition to learning a new programming language, especially if he is not a native English speaker.
38 replies
I am new to c# and need help
The easiest way would be to check each letter of the string within a loop to see if it isn't a "-" and append it to a new string. Do the same with a 2nd new string to the 2nd “-” and a 3rd new string to the end of the whole string. Now all you have to do is check which of the three strings you can parse into an integer and finally output the corresponding message.
38 replies
I am new to c# and need help
There you can look up all the string-methods (in german) for the task: https://learn.microsoft.com/de-de/dotnet/api/system.string?view=net-7.0#methods
I would consider Compare() as a possible candidate, but a few properties are quite interesting too. You can also loop through the string to check whether the character "-" is included twice and whether the last string can be parsed into an integer.
38 replies