Feedback

ist ein Char ein druckbares Zeichen?

Sprache: C#

Die Funktion ermittelt ob der übergebene Character ein druckbares Zeichen aus der ASCII Tabelle ist.
/// <summary>
/// Determines whether the character is printable
/// </summary>
/// <param name="candidate">The candidate.</param>
/// <returns>
/// 	<c>true</c> if [is printable character] [the specified candidate]; otherwise, <c>false</c>.
/// </returns>
private bool IsPrintableCharacter(char candidate)
{
    return !(candidate < 0x20 || candidate > 127);
}
/// <summary>
/// Determines whether the character is printable
/// </summary>
/// <param name="candidate">The candidate.</param>
/// <returns>
/// 	<c>true</c> if [is printable character] [the specified candidate]; otherwise, <c>false</c>.
/// </returns>
private bool IsPrintableCharacter(char candidate)
{
    return !(candidate < 0x20 || candidate > 127);
}

2 Kommentare

  1. Es geht noch schlichter:
    [code]return x >= 0x20 && x <= 127;[/code] Davon abgesehen ist char in C# ein 16bit-Unicode-Wert. Durch die Methode wird also nur für einen sehr kleinen Teil der druckbaren Zeichen true zurückgegeben.