❔ ✅ 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
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.
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...
Regex Class (System.Text.RegularExpressions)
Represents an immutable regular expression.
No worries, Regex is not a particularly advanced subject, but also not necessarily something you would come across naturally.
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
I should be able to figure it out on my own
This would be a simple example, although I don't know your exact needs.
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
Yw
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).
Ooh that's handy
Thanks
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!
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?
I think !close
I keep forgetting what the actual command is.
Closed it, yep it's close
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.