Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // replace special chars ("\r", "\n") with space
- function replaceSpecialChars(str) {
- var charArray = str.toCharArray();
- var filteredCharArray = [];
- for (var i = 0; i < charArray.size(); i++) {
- var filteredChar = charArray[i];
- if (charArray[i] == 0x0d) { // or '\r' or '\u000d'
- filteredChar = ' ';
- // collapse "\r\n" into a single space
- if (i+1 < charArray.size() && charArray[i+1] == 0x0a) {
- i++;
- }
- } else if (charArray[i] == 0x0a) { // or '\n' or '\u000a'
- filteredChar = ' ';
- }
- filteredCharArray.add(filteredChar);
- }
- return StringUtil.charArrayToString(filteredCharArray);
- }
- // Set the label of the data field here.
- function testCase() {
- var testString = "The\r\nquick\nbrown\rfox";
- System.println(testString.find("\r\n")); // prints: 3
- System.println(testString);
- // prints:
- /*
- The\r
- quick
- brown\rfox
- */
- // Connect IQ translates \r to literal "\r" in console, and
- // prints "\r" as box char on watch
- System.println(replaceSpecialChars(testString));
- // prints:
- /*
- The quick brown fox
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment