2

PurchPackingSlipJournalCreate class -> initHeader method have a line;

vendPackingSlipJour.PackingSlipId = purchParmTable.Num;

but i want when i copy and paste ' FDG 2020 ' (all blanks are tab character) in Num area and click okey, write this value as 'FDG2020' in the PackagingSlipId field of the vendPackingSlipJour table.

I tried -> vendPackingSlipJour.PackingSlipId = strRem(purchParmTable.Num, " "); but doesn't work for tab character.

How can i remove all whitespace characters from string?

1 Answer 1

5

Version 1

Try the strAlpha() function.

From the documentation:

Copies only the alphanumeric characters from a string.


Version 2

Because version 1 also deletes allowed hyphens (-), you could use strKeep().

From the documentation:

Builds a string by using only the characters from the first input string that the second input string specifies should be kept.

This will require you to specify all desired characters, a rather long list...


Version 3

Use regular expressions to replace any unwanted characters (defined as "not a wanted character"). This is similar to version 2, but the list of allowed characters can be expressed a lot shorter.

The example below allows alphanumeric characters(a-z,A-Z,0-9), underscores (_) and hyphens (-). The final value for newText is ABC-12_3.

str badCharacters = @"[^a-zA-Z0-9_-]"; // so NOT an allowed character
str newText = System.Text.RegularExpressions.Regex::Replace('  ABC-12_3 ', badCharacters, '');

Version 4

If you know the only unwanted characters are tabs ('\t'), then you can go hunting for those specifically as well.

vendPackingSlipJour.PackingSlipId = strRem(purchParmTable.Num, '\t');
4
  • Hi Sander, thanks for your answer but unfortunately our num values have -(hyphen) character sometimes. Is there any other way ?
    – Mumble
    Commented Sep 4, 2020 at 5:42
  • Answer updated to show how to handle any remaining unwanted characters.
    – Sander
    Commented Sep 4, 2020 at 6:15
  • no no, hyphens aren't unwanted characters. When i use strAlpha() hyphens removed. Bu i want remove only whitespace characters, not other non alphanumeric characters
    – Mumble
    Commented Sep 4, 2020 at 6:21
  • 1
    Answer updated with 3 more options. Take your pick.
    – Sander
    Commented Sep 4, 2020 at 7:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.