0
working with strings - help
I need help with this exercise which I try to do as it is in the code I shared but it generates an error. The problem mentions the following: In the RPG game you are playing, the player-character name must not exceed 10 characters in length. Write a program to take the player's character as input and abbreviate it from the 10th character if the name is longer than 10 characters. Generate the final result. Input example DragonBorn126 Output example DragonBorn Use the Remove () method to remove extra characters. Don't forget to reassign the formatted string to the name variable. This is my code: https://code.sololearn.com/ctfze852dNvD/?ref=app
5 odpowiedzi
+ 2
if (name.Length > 10) {
name = name.Remove(10);
}
Console.WriteLine(name);
+ 1
there's an error if the input string is less than 10 char length...
you must test if input string length (name.Length) is greater than 10 and use Remove() only if true ;)
+ 1
visph Excellent! only one condition was missing so that the code will execute correctly preventing exceptions. Thank you
0
no error for me, and correct output for input example ^^
0
visph. Exactly, in the exercise here there is no error but in the module the output does generate an error, and it is strange because that error should not appear if everything is fine here. I don't know what other solution can be implemented. I appreciate your suggestions.