How to replace a text string with another string value in C# .NET Framework
1 min readFeb 9, 2020
Today’s lightning-fast lesson will cover how to replace a string within some text with a different string. Think search and replace.
How shall we get started? First install our API client package with this console command.
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0
Now we just have to call EditTextReplaceSimple, which we have laid out 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 EditTextReplaceSimpleExample{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 ReplaceStringSimpleRequest(); // ReplaceStringSimpleRequest | Input requesttry{// Replace a string in text with another string valueReplaceStringSimpleResponse result = apiInstance.EditTextReplaceSimple(request);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditTextApi.EditTextReplaceSimple: " + e.Message );}}}}
Done! Wow, that was easy. With all that time you just saved, you should spend a couple minutes browsing our other tutorials. For all your document editing needs in C#, we’ve got you covered.