1

I have a list of values that look like this;

12345678/12345

On all of the ~160 lines in the list, I want to remove the '/' and the value after it, to be left with just the first bit before the /, on each line.

What is the best way to do this?

I've looked at the HELP pages for Replace and Change, but I can't ascertain how I would reference the first value before the '/'.

Thank you in advance.

Jack McCauley
  • 43
  • 1
  • 9
  • As a sidenote, all of the values are of the same length, before and after the '/', if that helps / makes any difference. – Jack McCauley Feb 24 '20 at 11:15
  • Are you reading these as variables in a program or as a Select list? I would probably use FIELD(Value,'/',1) to return everything before the whack. I could get more specific if you provide where you are trying to get at this. – Van Amburg Feb 24 '20 at 23:34
  • Hi @VanAmburg - thanks for your reply. They are in a select list. – Jack McCauley Feb 25 '20 at 11:55

1 Answers1

2

Regular Expressions isn't really a strong point of the U2 line, but what it IS good as it using delimiters to separate strings. You mentioned that this is in a select list and based on your criteria you could do it one of two ways.

  1. Value is delimited by a forward slash
  2. Delimiter is always in the same character position of the string.
  3. Values appear in a Select List. (which I assume means that they are IDs in a file, for this exercise we will call that file FOO.

If you know that the forward slash is only used as a delimiter and does not exist in the string before or after the delimiter position you mentioned is consistent you can use FIELD which allows you to essentially split the string on a character into a string array and reference one of more values of that array to be returned.

SELECT FOO SAVING EVAL "FIELD(@ID,'/',1)"

or if the value repeats and you want to remove duplicates

SELECT FOO SAVING UNIQUE EVAL "FIELD(@ID,'/',1)"

If you can't guarantee that there are no forward slash you can just use the character position reference. This is probably the best choice with limited knowledge.

SELECT FOO SAVING EVAL "@ID[1,8]"

or

SELECT FOO SAVING UNIQUE EVAL "@ID[1,8]"
Van Amburg
  • 1,207
  • 9
  • 15