Sunday, June 16, 2024

way to remove special characters from a string using X++

static void RemoveAllSpecialChararcters(Args _args)
{
	str sometext = "ABC#DE%F_$#G@1&23";

	str x = System.Text.RegularExpressions.Regex::Replace(sometext, @"[#,_,$,%,@,&]”, """);
	info(x);
}
static void Dev_ReplaceTxt(Args _args)
{
	TextBuffer buffer = new TextBuffer();
	Str message;
	;

	message = " hi hello's how r u's ";
	message += " How r u doing's wujer's * ? ' what ur mot's anbej's";

	buffer.setText(message);
	buffer.replace("[*?']","\\'"); // replace special character with escape sequence
	info(buffer.getText());

}

strRem('String','*');

If you want to delete the special characters from string, you can use "strAlpha" function. This copies only the alphanumeric characters from a string.

Ex : info(strFmt("%1", strAlpha("?a*b!!!!cD123.")));

results in "abcD123".

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8