C
C#2y ago
Chris TCC

❔ ✅ filtering, dissecting a string for processing

Not sure how to search for this online, so I'm asking here. I have a user input system, and I want to figure out how to dissect the string in code. Basically, there are different types of inputs the user can give. Examples would be: <Text> @text #textand3numbers General messages with symbols I'd like to be able to differentiate these types of inputs, and do different actions. I was thinking maybe using Contains(); but it can't differentiate a @text from a regular string that includes the @ symbol. Is that even possible to do this without overcomplicating things?
17 Replies
hiyosilver
hiyosilver2y ago
Sounds like a job for Regex. Shouldn't be too hard to define a pattern for "starting with @ followed by 1 or more letters" or whatever else you need. I'd say that's not overcomplicating it.
Chris TCC
Chris TCC2y ago
Regex? Sorry, I'm new to c#, so I'm not too familiar with many mid- to advanced concepts Well, I say I'm new but I've been coding on and off for about half a decade now, but I'm self-taught...
hiyosilver
hiyosilver2y ago
No worries, Regex is not a particularly advanced subject, but also not necessarily something you would come across naturally.
Chris TCC
Chris TCC2y ago
Yup, that seems like what I was looking for I didn't know how to word it for Google so I had trouble finding it... Thanks so much
hiyosilver
hiyosilver2y ago
Chris TCC
Chris TCC2y ago
I should be able to figure it out on my own
hiyosilver
hiyosilver2y ago
This would be a simple example, although I don't know your exact needs.
Chris TCC
Chris TCC2y ago
Hopefully That's fair, I was just looking for a term or something that I could use to learn the system. The word regex is all I need Appreciate the fast response, thanks so much mate
hiyosilver
hiyosilver2y ago
Yw
hiyosilver
hiyosilver2y ago
btw if you want to fiddle around with it, I recommend https://regexr.com/
RegExr
RegExr: Learn, Build, & Test RegEx
RegExr is an online tool to learn, build, & test Regular Expressions (RegEx / RegExp).
Chris TCC
Chris TCC2y ago
Ooh that's handy Thanks
hiyosilver
hiyosilver2y ago
It also explains each part of your current regex to allow you to follow whats happening a little better. Good luck, and dont hesitate to ask if you are stuck!
Chris TCC
Chris TCC2y ago
Good to know this stuff for down the line Right now I'm working on some code for a bot, that's why Any way for me to close this, or it'll close on its own?
hiyosilver
hiyosilver2y ago
I think !close I keep forgetting what the actual command is.
Chris TCC
Chris TCC2y ago
Closed it, yep it's close
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
More Posts