Open In App

C# | Char.IsSymbol() Method

Last Updated : 31 Jan, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

In C#, Char.IsSymbol() is a System.Char struct method which is used to check whether a Unicode character is a valid symbol defined under UnicodeCategory as MathSymbol, CurrencySymbol, ModifierSymbol, or OtherSymbol or not. This method can be overloaded by passing different types and number of arguments to it.

  1. Char.IsSymbol(Char) Method
  2. Char.IsSymbol(String, Int32) Method

Char.IsSymbol(Char) Method

This method is used to check whether a specified Unicode character matches with any valid symbol in UnicodeCategory or not. If it matches then it returns True otherwise return False.

Syntax:

public static bool IsSymbol(char ch);

Parameter:

ch: It is required unicode character of System.char type which is to be checked for a valid symbol.

Return Type: The method returns True if the specified Unicode character is a valid symbol, otherwise returns False. The return type of this method is System.Boolean.

Example:




// C# program to illustrate the
// Char.IsSymbol(Char) Method
using System;
  
class GFG {
  
    // Main Method
    static public void Main()
    {
  
        // Declaration of data type
        bool result;
  
        // checking if plus sign
        // is symbol or not
        char ch1 = '+';
  
        result = Char.IsSymbol(ch1);
        Console.WriteLine(result);
  
        // checking if dollar sign
        // is symbol or not
        char ch2 = '$';
  
        result = Char.IsSymbol(ch2);
        Console.WriteLine(result);
  
        // checking if @
        // is symbol or not
        char ch3 = '@';
  
        result = Char.IsSymbol(ch3);
        Console.WriteLine(result);
    }
}


Output:

True
True
False

Char.IsSymbol(String, Int32) Method

This method is used to check whether a character in the specified string at the specified position is a valid symbol or not. If it is a symbol according to the Unicode standard then it returns True otherwise returns False.

Syntax:

public static bool IsSymbol(string str, int index);

Parameters:

Str: It is the required string of System.Stringtype whose character is to be checked.
index: It is the position of character in specified string. Type of this parameter is System.Int32.

Return Type: The method returns True if the character at specified index in the specified string is a valid symbol according to the Unicode standard, otherwise returns False. The return type of this method is System.Boolean.

Example:




// C# program to illustrate the
// Char.IsSymbol(String, Int32) Method
using System;
  
class GFG {
  
    // Main Method
    static public void Main()
    {
  
        // Declaration of data type
        bool result;
  
        // checking for symbol in
        // a string
        string str1 = "www.GeeksforGeeks.org";
        result = Char.IsSymbol(str1, 3);
        Console.WriteLine(result);
  
        // checking for symbol in
        // a string
        string str2 = "geeks+";
        result = Char.IsSymbol(str2, 5);
        Console.WriteLine(result);
    }
}


Output:

False
True

Reference: https://docs.microsoft.com/en-us/dotnet/api/system.char.issymbol?view=netframework-4.7.2



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads