C
C#2y ago
asianaf

❔ I'm not sure what's wrong with my code

I don't know why Thompson still pop up only T should be. (The blue outline is what I'm trying to do)
29 Replies
x0rld 👻 🎃
@ASIAN af try with surname[0]
mtreit
mtreit2y ago
What does Remove do?
asianaf
asianafOP2y ago
it removes the word in that Text or string
mtreit
mtreit2y ago
String.Remove Method (System)
Returns a new string in which a specified number of characters from the current string are deleted.
mtreit
mtreit2y ago
Strings are immutable.
mtreit
mtreit2y ago
asianaf
asianafOP2y ago
like this right?
mtreit
mtreit2y ago
Remove produces a new string. You aren't looking at the return value though. You are calling Remove and throwing away the result.
asianaf
asianafOP2y ago
so I still need to grab it?
mtreit
mtreit2y ago
You need to assign the result to something, yes.
MODiX
MODiX2y ago
mtreit#6470
REPL Result: Success
var s = "abc";
s = s.Remove(1, 1);
Console.WriteLine(s);
var s = "abc";
s = s.Remove(1, 1);
Console.WriteLine(s);
Console Output
ac
ac
Compile: 513.050ms | Execution: 65.887ms | React with ❌ to remove this embed.
asianaf
asianafOP2y ago
or could I just add it to lbloutput?
asianaf
asianafOP2y ago
like this
mtreit
mtreit2y ago
Yes you can do that as well.
asianaf
asianafOP2y ago
oh this stuff is getting hard
asianaf
asianafOP2y ago
another question how do I remove the starting number/word?
mtreit
mtreit2y ago
That line of code you wrote where you are doing everything in one line: I avoid writing code like that. I think it's better to break up each task you are doing into smaller tasks and then put them all together. Then it's easier to debug and to reason about what's going on in each line of code. Which starting number ?
asianaf
asianafOP2y ago
if you look at the image 980529 I'm trying to remove 9
mtreit
mtreit2y ago
You can use string.Substring
MODiX
MODiX2y ago
mtreit#6470
REPL Result: Success
var s = "980529";
s = s.Substring(1);
Console.WriteLine(s);
var s = "980529";
s = s.Substring(1);
Console.WriteLine(s);
Console Output
80529
80529
Compile: 514.484ms | Execution: 64.253ms | React with ❌ to remove this embed.
asianaf
asianafOP2y ago
OOh okay I did it like this
asianaf
asianafOP2y ago
asianaf
asianafOP2y ago
doesn't T start as 0? like Thompson 01234567
mtreit
mtreit2y ago
Yes, "T" is at index 0 in the string "Thompson" if that's what you're asking. I'm not sure I understood the question.
asianaf
asianafOP2y ago
sorry for the bad english but yeah that's what I'm trying to sya say then could I do Remove(0)?
mtreit
mtreit2y ago
Returns a new string in which all the characters in the current instance, beginning at a specified position and continuing through the last position, have been deleted.
If you read that definition, what does it mean to pass 0? In other words: "Start at position zero and delete everything from that position to the end of the string." So passing zero deletes everything. If you're not sure what a method does, you should definitely read the documentation for it:
mtreit
mtreit2y ago
String.Remove Method (System)
Returns a new string in which a specified number of characters from the current string are deleted.
asianaf
asianafOP2y ago
oh okay thanks I'll read through it
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server