C#: How to list all possible capital/non-capital combinations of a name

Watch this thread
Darya.
Badges: 17
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#1
Report Thread starter 1 year ago
#1
Name:  Screenshot 2020-11-17 095318.png
Views: 16
Size:  9.1 KB
In the above screenshot I've got an if statement where if the username is Darya, it welcomes me as an administrator, and if not, it welcomes me as a basic user. Unfortunately, I've only listed "Darya", "darya" and "DARYA" as the combinations that will welcome as an administrator. However, if the username is "dARyA" or any other combination of those 5 letters in that order but not with the specific capitalizations listed in the if statement, it will only say that I'm a basic user. Is there any way of saying if the username is *any* version of the letters d, a, r, y and a in that order, using any capitalization, it will say that I'm an administrator?
At the moment the only route I can think of is to manually write every possible form of Darya using all the possible capitalizations, however there are tens of combinations and I really don't think it's efficient to spend a lot of time doing that.
So does anyone have any way to recognize that any form of Darya is an administrator without listing all of them?

Thanks!!
Last edited by Darya.; 1 year ago
0
reply
Strange5050
Badges: 17
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#2
Report 1 year ago
#2
It would depend whether you need any variation to be unique. E.g if Dayra is different from DAyra etc.. If this doesn't matter you can simply force the input to lower case and check against that. E.g:

Code:
username = username.ToLower(); // <-- This is an actual method you can use on strings
if (username == "dayra") 
{
    // etc.. etc..
}
Of course, you could do this the opposite way and use 'ToUpper()' as well. This way you can simply check against 1 variation.

Relevant documentation:
https://docs.microsoft.com/en-us/dot...r?view=net-5.0
https://docs.microsoft.com/en-us/dot...r?view=net-5.0
Last edited by Strange5050; 1 year ago
1
reply
Darya.
Badges: 17
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#3
Report Thread starter 1 year ago
#3
(Original post by Strange5050)
It would depend whether you need any variation to be unique. E.g if Dayra is different from DAyra etc.. If this doesn't matter you can simply force the input to lower case and check against that. E.g:

Code:
username = username.ToLower(); // <-- This is an actual method you can use on strings
if (username == "dayra") 
{
    // etc.. etc..
}
Of course, you could do this the opposite way and use 'ToUpper()' as well. This way you can simply check against 1 variation.

Relevant documentation:
https://docs.microsoft.com/en-us/dot...r?view=net-5.0
https://docs.microsoft.com/en-us/dot...r?view=net-5.0
Oh that works perfectly, thanks so much!!
1
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

How did your AQA A-level Psychology Paper 1 go?

Loved the paper - Feeling positive (281)
41.63%
The paper was reasonable (281)
41.63%
Not feeling great about that exam... (62)
9.19%
It was TERRIBLE (51)
7.56%

Watched Threads

View All