TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C# char.IsSeparator Example

This C# example program shows the char.IsSeparator method. It shows all the separator characters.

Char.IsSeparator. What does the char.IsSeparator method do?

Is it useful for any specific tasks in your C# programs? IsSeparator refers to the Unicode concept of separator characters, which separate words.

Example. The simplest overload of char.IsSeparator receives one argument: a char. It then returns whether or not the char is a separator. A space is a separator. Other kinds of separators such as periods are not separators in Unicode.

Next: The program further outputs all the possible separator chars. Most of them cannot be displayed in the console.

Console

C# program that uses char.IsSeparator

using System;

class Program
{
    static void Main()
    {
	Console.WriteLine(char.IsSeparator(' '));
	Console.WriteLine(char.IsSeparator('.'));

	for (char c = char.MinValue; c < char.MaxValue; c++)
	{
	    if (char.IsSeparator(c))
	    {
		Console.WriteLine("{0} {1}", c, (int)c);
	    }
	}
    }
}

Output

True
False
  32
  160
? 5760
? 6158
  8192
  8193
  8194
  8195
  8196
  8197
  8198
? 8199
? 8200
? 8201
? 8202
? 8232
? 8233
? 8239
? 8287
  12288

Paths. File paths also have a concept of separators. These are not the same kind of separators as are described in Unicode. If you want to detect path separators, do not use char.IsSeparator.

Path

Summary. The separators detected by char.IsSeparator are whitespace characters that separate words. The most common separator is the space character. In many programs, testing against the space directly would be better than using char.IsSeparator.

Tip: In additional cases, the char.IsWhitespace method (covered in a separate article) is best.

char.IsWhiteSpace


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf