Case of the Non-Breaking Space (Part II)

In the first part of the case of the non-breaking space I developed a script to show what the unicode values were for a given string.

This article is the next evolution of the solution to removing a non-breaking space from your code. The script below is designed for Linqpad.

This script will get the text from the Clipboard and then replace the Non-Breaking Space with a Space. Finally it will copy the converted text back up to the Clipboard in order to paste it into your application \ code.

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

void Main()
{
	var input= Clipboard.GetText();
	var searchChar = '\u00A0';
	var replaceChar = '\u0020';

	var converted = input.Replace(searchChar,replaceChar).Dump();
	Clipboard.SetText(converted);

    /* Optional Function to Show the Proces
	var contents = ProcessInput(input);
	contents.Dump(); */
}

// This Function will List the Unicode Values of the Provided String
public List<CharacterDetail> ProcessInput(string value)
{
	Func<char, string, string> ConvertToUnicode = (t, p)
        => $"{p}{Convert.ToUInt16(t):X4} ";

	var results = value.Select(t => new CharacterDetail
	{
		Character = t,
		UnicodeValue = ConvertToUnicode(t, "U+"),
		UnicodeConversion = ConvertToUnicode(t, @"\u")
	}).ToList();

	return results;
}

// Class to store the Unicode Values
public class CharacterDetail
{
	public char Character { get; set; }
	public string UnicodeValue { get; set; }
	public string UnicodeConversion {get;set;}
}
Code Generate TSql Alter Table Statement Case of the non-breaking space part I