Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Indexof(', ', int32, int32, stringcomparison)

I have a customized textbox that autosuggests and shows listbox. I want it to suggest every after a comma with space ', ' not just a space or a comma. Thanks in advance. I'm new to c# btw. Im using winforms.

What I have tried:

None yet. I'm still reasearching for materials and knowledge for this.
Posted
Updated 28-May-18 4:11am

Yes: String.IndexOf Method (String) (System)[^]
C#
int index = myString.IndexOf(", ");
 
Share this answer
 
Comments
Aurelio Nogar 29-May-18 8:56am    
A follow up question this is. How about spliting a string by 2 char?

var result = str.Split(new char[] {', '});
See the list of the String.IndexOf Method (System)[^] overloads. The official documentation is always the first to be read when being unsure. It contains also often a list of related functions that might do what you want when the initial one does not.

If you want to search for ", ", use one of the IndexOf methods accepting a string:
Quote:
Reports the zero-based index of the first occurrence of the specified string in the current String object.
Note also that it is not necessary to use an overload accepting a comparisonType for a search string containing only ASCII characters.

If you want to search for more complex cases (like a comma optionally followed by one or more spaces), have a look at regular expressions. But when a task can be done with a basic function like here, use that.
 
Share this answer
 
Comments
Aurelio Nogar 29-May-18 8:56am    
A follow up question this is. How about spliting a string by 2 char?

var result = str.Split(new char[] {', '});
Jochen Arndt 29-May-18 9:02am    
Same answer. See the overloads for String.Split(), here String.Split Method (String[], StringSplitOptions)
OriginalGriff 29-May-18 9:10am    
I'd upvote that, if you could upvote comments...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900