Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Char.IsSymbol() Method in C#
The Char.IsSymbol() method in C# determines whether a specified character is categorized as a symbol character. Symbol characters include mathematical symbols, currency symbols, and other non-alphanumeric characters that are not punctuation or control characters.
Syntax
The method has two overloads −
public static bool IsSymbol(char c); public static bool IsSymbol(string str, int index);
Parameters
c − The Unicode character to evaluate.
str − A string containing the character to evaluate.
index − The position of the character to evaluate in the string.
Return Value
Returns true if the character is categorized as a symbol; otherwise, false.
Using IsSymbol() with Single Character
Example
using System;
public class Demo {
public static void Main() {
char[] testChars = {'P', '+', '$', '?', '©', '.', '5'};
foreach (char val in testChars) {
bool res = Char.IsSymbol(val);
Console.WriteLine($"Character '{val}' is symbol: {res}");
}
}
}
The output of the above code is −
Character 'P' is symbol: False Character '+' is symbol: True Character '$' is symbol: True Character '?' is symbol: True Character '©' is symbol: True Character '.' is symbol: False Character '5' is symbol: False
Using IsSymbol() with String and Index
Example
using System;
public class Demo {
public static void Main() {
string testString = "Price: $50 + tax ? 10%";
Console.WriteLine($"String: {testString}");
Console.WriteLine("Symbol analysis:");
for (int i = 0; i
The output of the above code is −
String: Price: $50 + tax ? 10%
Symbol analysis:
Position 7: '$' is a symbol
Position 11: '+' is a symbol
Position 17: '?' is a symbol
Common Use Cases
The IsSymbol() method is commonly used for −
Text Processing − Identifying and handling mathematical or currency symbols in documents.
Input Validation − Checking if user input contains unwanted symbol characters.
String Parsing − Separating symbols from alphanumeric content during text analysis.
Example - Filtering Symbols from Text
using System;
using System.Text;
public class Demo {
public static void Main() {
string text = "Total: $100 + $25 = $125 (tax included)";
StringBuilder filtered = new StringBuilder();
foreach (char c in text) {
if (!Char.IsSymbol(c)) {
filtered.Append(c);
}
}
Console.WriteLine($"Original: {text}");
Console.WriteLine($"Filtered: {filtered}");
}
}
The output of the above code is −
Original: Total: $100 + $25 = $125 (tax included) Filtered: Total: 100 25 125 (tax included)
Conclusion
The Char.IsSymbol() method in C# identifies symbol characters like mathematical operators, currency symbols, and special characters. It's useful for text processing, input validation, and parsing operations where distinguishing symbols from letters, digits, or punctuation is required.
