C
C#2w ago
Headless

Manipulating Strings

I'm new to c# and am learning online, I'm currently trying to wrap my head around Substrings and using different methods to manipulate strings, currently I'm stuck trying to use .ToUpper() on an existing variable, that is also composed of other variables. Example in image Thanks! tldr; I need to use the .ToUpper() method on the cameraDirections variable
No description
12 Replies
Joschi
Joschi2w ago
What exactly is your problem here? Why cant you just call ToUpper on that string?
Headless
HeadlessOP2w ago
Im just not sure where I put it on the actual string, or if I have to specify it in the previous variables?
Joschi
Joschi2w ago
Ok what exactly is your goal here? Can you post the exact final output you expect?
Headless
HeadlessOP2w ago
It's for a lesson, I'll post the question
Headless
HeadlessOP2w ago
No description
Headless
HeadlessOP2w ago
I think I have it right, with just using cameraDirections = cameraDirection.ToUpper() to convert that to upper, however I'm not sure if theres a more efficient way to do it?
Joschi
Joschi2w ago
The code on the right is your code correct?
Headless
HeadlessOP2w ago
Yeah
Joschi
Joschi2w ago
Strings in C# are immutable. Meaning you cannot change the actual string itself, just creating new ones. So what you want to do is extract the parts you want to change, change them and then rebuild the full string. You are more or less doing it, but I guess your input should be the original unmodified string. Without any ToUpper mixed in there like you did. There are ways of doing this more efficient, but you should not worry about that right now.
Headless
HeadlessOP2w ago
Yeah okay, thanks that makes sense to me, To me this just feel dumb to do this way, if I wanted to search for "Close on" In capitalized letters I would just type is as "CLOSE ON" instead of converting it....but the question wants me to do it that way, it just threw me for a bit of a loop, but i'll just continue through the question cause it's more or less correct. Thank you for your help!
Joschi
Joschi2w ago
The idea would be, that you have a full script, 300+ pages long. Now you want to convert all the camera directions and positions into the case you prefer. It's way faster writing code for you to do that. What you got there is just the bases for doing it.
Headless
HeadlessOP2w ago
Yeah, that makes sense when you put it like that, its hard understanding without someone to actually explain why im doing it or somewhere where it could be used :KEKW:. Thanks again
Want results from more Discord servers?
Add your server