60 Replies
@Pobiega
Yeah, you can't do that. Strings in C# are immutable
Meaning you need to produce a new string
oh
in the RemoveExclaimation or in the main
Former
where is that
i thought turning it into an array would help
make the userinput a char array, then give that char array to the function
i thought i did that
thats also a bad idea.
your input is a string. The "law of least surprise" says that your output should be a string without exclamations
i produced a new string
however i think i've done it wrong
correct
also, setting it to a space isnt the same as removing it
do you just want to replace the
!
with
or do you want a string without !
in it?i want to remove it
okay
but i thought i had to replace it to do that
then you need to build a new string
you needed to do that before too, to be clear
since strings are immutable
that means it can't change doesnt it
correct
i've done this before and it worked
ToCharArray()
it converts the string to a char[]
but an array is fixed-size!
that means you cant remove an item from it, just clear it
so !!hello!!
would become hello
not hello
right okay
so have i done this completely wrong
Well, depends on what your goal was
Most people would expect you to take a string in and return a new string
my goal is to remove the !
Fully remove, right?
yes
Not just replace
Ok
no
There is a class called
StringBuilder
It's very commonly used when you need to "build" a stringokay ill make it now
you mean like this
Haha, no there already is one in .NET
You don't need to make your ow
oh okay
Yup
Now change the code to use the string builder
im not sure what string builder does exactly
on a new row, type
sb.
and see what pops upsee that list of things? scroll through it
so far,
Append
is a very good method suggestionthere is remove
the idea is that you progressively build a copy of the original string, but when you encounter a
!
, you DONT add it
or that, copy the entire string and remove !
but I prefer the first approachokay ive used append
what does it do?
what do you think?
with that name
fix?
we have a class called
StringBuilder
. it builds strings, right?oh build
what does
append
mean, in english?
it means "to add at the end"i did not know that
now you do 🙂
you're teaching me coding and english
When do I get my teaching license?
:d
soon
right so ive put
maybe start over from here
you have a bunch of old code that doesnt belong and is just confusing you
okay ive changed it
also, if you prefer, we could go to a voice channel and screen share
okay lets do that
#vc-1
i've got 2 exams on monday, so im going to revise the othe for the rest of the night, but will be back to computer science tomorrow @Pobiega
bah
stop being sensible
😄
good luck!