Skip to Content

Need to replace short dash between numbers without replacing the short dash between words

Hi there

Here is an example of a line of text: Bio-synthetic valve, c. 1995-2001

In the above statement, I want to replace the short dash that appears between the years, but not the one that appears in the conjoined word. Is there a way I can search out 2 numeric characters followed by short dash followed by 2 numeric characters and replace the short dash with a longer em dash?

Desired end result: Bio-synthetic valve, c. 1995—2001

Any help would be greatly appreciated!



Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Apr 24, 2018 at 12:19 AM

    Yes, there is a way to do this using a couple of variables and a loop in a formula. It looks something like

    StringVar result := ' ';
    Local NumberVar strLen := Length({MyTable.MyField});
    Local NumberVar i := 1;
    While i < strLen do
      if {MyTable.MyField}[i] <> '-' then
        result := result + {MyTable.MyField}[i]
        if (i < strLen) and IsNumeric({MyTable.MyField}[i-1]) and 
          IsNumeric ({MyTable.MyField}[i + 1]) then
          result := result + chr(336)
          result := result + {MyTable.MyField}[i]

    Note that "chr(336)" is an emdash in the Arial font. You'll want to check whatever font you're using to determine what character you need to use.


    Add comment
    10|10000 characters needed characters exceeded

  • Apr 24, 2018 at 07:27 AM

    Or you could just test for numbers

    If isnumeric(replace(yourfield,"-", "") then replace(yourfield,"-", "chr(336)") else yourfield


    Add comment
    10|10000 characters needed characters exceeded

    • Hi there Ian

      An example of the entered field content is:

      Bio-synthetic valve, c. 1995-2001

      I need the dash between the numerical values (ie. between 1995 and 2001) to be an em dash, so I figured the simplest way to do that would be to ask Crystal to turn any dash that comes after two numerals and before 2 numerals (ie. is in between them), to turn that dash into an em dash. The reason why I nominate 2 digits is that there may be cases where the user enters only 2 digits in the date range, so all possibilities are covered if I just search on 2 rather than 4.

      Hope that makes sense!