How to remove whitespace from a text string in C# .NET Framework

Cloudmersive
1 min readFeb 9, 2020

--

Today we will cover a quick and easy method to strip out any and all whitespace characters from text. Prepare to be amazed at just how quick and easy it will be.

First off, we need to install our API client. No problem, we just paste this command into Package Manager’s console.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

Now, we just need to call EditTextRemoveAllWhitespace. We have laid out the coding for this below.

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class EditTextRemoveAllWhitespaceExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new EditTextApi();var request = new RemoveWhitespaceFromTextRequest(); // RemoveWhitespaceFromTextRequest | Input requesttry{// Remove whitespace from text stringRemoveWhitespaceFromTextResponse result = apiInstance.EditTextRemoveAllWhitespace(request);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditTextApi.EditTextRemoveAllWhitespace: " + e.Message );}}}}

And that’s it! All white space characters, including spaces and new lines, will be removed from your returned text.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet