Forum Discussion
Regex expression for replacing particular symbols in text- ®and ™
Hi Aaron-92 ,
Thanks for posting your issue here.
Here's how you can implement it within an ASP.NET Core controller action:
using Microsoft.AspNetCore.Mvc;
using System.Text.RegularExpressions;
namespace YourNamespace.Controllers
{
public class YourController : Controller
{
public IActionResult YourAction()
{
string input = "hello® this is a test™";
string pattern = "(®|™)";
string replacement = "<sup>$1</sup>";
string result = Regex.Replace(input, pattern, replacement);
ViewBag.Result = result; // Store the result in ViewBag or pass it to your view model
return View(); // Return the view where you want to display the result
}
}
}
Note :
- Make sure to replace Your Namespace, Your Controller, and Your Action with your actual application's namespaces, controller name, and action name.
Best Regards,
AddWebSolution