© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
17 replies
sonodan.

Searching a string for a substring containing operators

I'm trying to find how many times the string
"*"
"*"
occurs in a string I have.

I've tried a few different things including backslashes, but I found a stackoverflow solution saying a string literal should work:

var matches = response.Where(s => s.Contains(@""*"")).Count;
var matches = response.Where(s => s.Contains(@""*"")).Count;


I'm met with an error
Operator * cannot be applied to operands of type 'string' and 'string'
Operator * cannot be applied to operands of type 'string' and 'string'
. What's the best practice here to accomplish this?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Find all instances of a substring in a string
C#CC# / help
10mo ago
✅ Searching For a Book
C#CC# / help
10mo ago
✅ Getting a string from a text file and get the whole line containing the string
C#CC# / help
4y ago