Remove string after/before special character in D365fo X++
static void RemoveStringAfterSpecialChar(Args _args)
{
CustTable custTable;
while select * from custTable
{
str dataWithSpecialChar;
str dataBeforeSpecialChar;
dataWithSpecialChar = custTable.myStringField; // Replace 'myStringField' with your actual field name.
// Find the position of the special character (e.g., "-" in this example).
int specialCharPos = strScan(dataWithSpecialChar, "-", 1, strLen(dataWithSpecialChar));
if (specialCharPos > 0)
{
// Extract the part of the string before the special character.
dataBeforeSpecialChar = subStr(dataWithSpecialChar, 1, specialCharPos - 1);
}
else
{
// If no special character is found, keep the original string.
dataBeforeSpecialChar = dataWithSpecialChar;
}
// Update the record with the modified string.
custTable.myStringField = dataBeforeSpecialChar;
custTable.update();
}
}
Comments
Post a Comment