Case of the Non-Breaking Space (Part I)

The non breaking space prevents an automatic line break at its position. It is often used in word processing and office applications. The space is no different visually to a normal space character.

When this space appears in a Razor View it doesn't cause any errors until runtime. When the view is rendered it can fail or have strange behaviour on the layout.

Any Character can be converted into its Unicode value using .Net

  • Unicode Character 'Non Breaking Space' (U+00A0)
  • Unicode Character 'Space' (U+0020)

So how can you see whether you have a non-breaking space?

Script : Show Unicode Values

The script below can be used in Linqpad. It will get the text from the clipboard, convert each character to its Unicode value and then finally dump the object to the output window.

using System;
using System.Linq;
using System.Windows.Forms;

void Main()
	Func<char,string> ConvertToUnicode = (t) =>  $"U+{Convert.ToUInt16(t):X4} ";

	var input= Clipboard.GetText();
	var result = input.Select(t => new CharacterDetail
                       { Character = t,UnicodeValue = ConvertToUnicode(t) }).ToList();

public class CharacterDetail
	public char Character { get; set; }
	public string UnicodeValue { get; set; }


Below is an example output from running the script above.

Character UnicodeValue
v U+0076
o U+006F
i U+0069
d U+0064
m U+004D
a U+0061
i iU+0069
n U+006E
Case of the non-breaking space part II Create a Lottery Generator