How can SilkTest remove a Carriage Return or Line Feed character from a string?
The following 4Test function, RemoveCarriageReturn(), is designed to remove from a string all instances of the carriage-return character (ASCII character #13) and the line-feed character (ASCII #10).
[-] STRING RemoveCarriageReturn (STRING sOriginal, STRING sReplacement) [ ] [ ] STRING sResult = "" [ ] STRING sTemp [ ] INTEGER iCounter [ ] [-] for iCounter = 1 to Len(sOriginal) [ ] sTemp = sOriginal[iCounter] [ ] [-] if ( (Asc(sTemp) == 10) || (Asc(sTemp) == 13) ) [ ] sResult = sResult + sReplacement [-] else [ ] sResult = sResult + sTemp [ ] [ ] return sResult [ ]
The parameter sOriginal is the original string from which you want the carriage-return and line-feed characters removed.
The parameter sReplacement is the string that will replace the carriage return and the line feed: the string can be of any length, including length of zero. The following code would remove the character-return and line-feed characters from sMyString without replacing them with other characters:
sMyString = RemoveCarriageReturn (sMystring, "")
The function returns a copy of sOriginal, modified such that each instance of the character-return character and the line-feed character is replaced with sReplacement.
The function can be easily modified to remove just carriage returns, just line feeds, or any other individual characters.