C
C#2y ago
Jin

String Contain issue

So im trying to get a word in a string using Contain but its not getting the word, I havent found a workaround it or im just completely doing it wrong.
if (OtherUser != null)
{
string bio = OtherUser.Bio.Replace("\n","").Replace(" ","").Trim();
if (bio.Contains("OwlHouse#disc"))
{
await RespondAsync($"{Context.User.Mention} You have been verified.",ephemeral: true);
}
else
{
await RespondAsync($"{Context.User.Mention} You do not have the code in your Bio. \n`[ BIO ]` \n{bio}", ephemeral: true);
}
}
if (OtherUser != null)
{
string bio = OtherUser.Bio.Replace("\n","").Replace(" ","").Trim();
if (bio.Contains("OwlHouse#disc"))
{
await RespondAsync($"{Context.User.Mention} You have been verified.",ephemeral: true);
}
else
{
await RespondAsync($"{Context.User.Mention} You do not have the code in your Bio. \n`[ BIO ]` \n{bio}", ephemeral: true);
}
}
4 Replies
Connor
Connor2y ago
I may be wrong but it looks like there’s a space before and after the “#”
Henkypenky
Henkypenky2y ago
this is a perfect example to use the debugger place a breakpoint at string bio and see what the actual string is then just use a text editor to search for your desired word because this:
string bio = OtherUser.Bio.Replace("\n","").Replace(" ","").Trim();
string bio = OtherUser.Bio.Replace("\n","").Replace(" ","").Trim();
can produce anything how can we know it will have your desired word in it also, contains will not fail so the problem is in your string output 100%
MODiX
MODiX2y ago
Henkypenky#4865
REPL Result: Success
string bio = "1223312321-5415157*/-456/*/*4651-OwlHouse#disc-DSAE3412DASKIOCASUNUI12312321DASCZXCAWSEDASDSA";
if (bio.Contains("OwlHouse#disc"))
{
Console.WriteLine("Omg, yes it does");
}
string bio = "1223312321-5415157*/-456/*/*4651-OwlHouse#disc-DSAE3412DASKIOCASUNUI12312321DASCZXCAWSEDASDSA";
if (bio.Contains("OwlHouse#disc"))
{
Console.WriteLine("Omg, yes it does");
}
Console Output
Omg, yes it does
Omg, yes it does
Compile: 612.350ms | Execution: 35.149ms | React with ❌ to remove this embed.
Jin
JinOP2y ago
because it replied back the string in the screenshot. actually i think this might be the issue. yeah that was the issue.
Want results from more Discord servers?
Add your server