How to trim leading and trailing Whitespace from a Text String in Node.JS

Cloudmersive
1 min readApr 10, 2020

--

The goal of our tutorial today is to show you how to remove whitespace from the beginning and end of a given text string. Before you dust off your coding hat, what if I told you that we weren’t going to need much coding at all? With the help of a Cloudmersive API, we can get this done very easily indeed. Let’s look at how.

Installing our client is the first step. Simply activate this command for npm install.

npm install cloudmersive-convert-api-client --save

Now we can use editTextTrimWhitespace and provide it with our text string to trim.

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.EditTextApi();var request = new CloudmersiveConvertApiClient.RemoveWhitespaceFromTextRequest(); // RemoveWhitespaceFromTextRequest | Input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editTextTrimWhitespace(request, callback);

And we are already done!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet