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);
}
Alte URL:
/snippet/ist-ein-char-ein-druckbares-zeichen/125
Sehr schlichter Code, der aber sehr nutzbar ist. Kompliment!
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.