removal of spaces in between chars.

shulbert@littlejohnfrazer.com shulbert@littlejohnfrazer.com
Wed, 25 Aug 2004 17:19:14 +0100


the solutions provided either assume there's a fixed number of the character in the string (usually one) or are os specific.
here's a portable solution if speed is no problem:

<code>
def field1 char*6 = "A ! B"

def f-01 char = field1[1:1]
def f-02 char = field1[2:1]
def f-03 char = field1[3:1]
def f-04 char = field1[4:1]
def f-05 char = field1[5:1]
def f-06 char = field1[6:1]

def field2 char*6 = tru(f-01) &                   + tru(f-02) &                   + tru(f-03) &                   + tru(f-04) &                   + tru(f-05) &                   + tru(f-06)

</code>

field2 should have the value "A!B   ".
to get rid of a different char (!) and preserve spaces, use:

<code>

def field1 char*6 = "A ! B"

;using tilde but you could use any char
def d'sub char = "~"

def f-01 char = " " if "!" = field1[1:1] else d'sub if " " = field1[1:1] else field1[1:1]
def f-02 char = " " if "!" = field1[2:1] else d'sub if " " = field1[2:1] else field1[2:1]
def f-03 char = " " if "!" = field1[3:1] else d'sub if " " = field1[3:1] else field1[3:1]
def f-04 char = " " if "!" = field1[4:1] else d'sub if " " = field1[4:1] else field1[4:1]
def f-05 char = " " if "!" = field1[5:1] else d'sub if " " = field1[5:1] else field1[5:1]
def f-06 char = " " if "!" = field1[6:1] else d'sub if " " = field1[6:1] else field1[6:1]

def field2 char*6 = tru(f-01) &                   + tru(f-02) &                   + tru(f-03) &                   + tru(f-04) &                   + tru(f-05) &                   + tru(f-06)

def g-01 char = f-01 if d'sub <> f-01 else " "
def g-02 char = f-02 if d'sub <> f-02 else " "
def g-03 char = f-03 if d'sub <> f-03 else " "
def g-04 char = f-04 if d'sub <> f-04 else " "
def g-05 char = f-05 if d'sub <> f-05 else " "
def g-06 char = f-06 if d'sub <> f-06 else " "

def field3 char*6 = g-01 &                   + g-02 &                   + g-03 &                   + g-04 &                   + g-05 &                   + g-06

</code>

field3 should now contain "A  B  "
regards,
stephen.

Littlejohn Frazer
Chartered Accountants
1 Park Place
Canary Wharf
London
E14 4HJ

Tel: 020 7987 5030
Fax: 020 7987 9707
Web: www.littlejohnfrazer.com


The information contained in this communication is confidential and may
be legally privileged. It is intended solely for the use of the
individual or entity to whom it is addressed and others authorised to
receive it.  If you are not the intended recipient you are hereby
notified that any disclosure, copying, distribution or taking of any
action in reliance on the contents of this information is strictly
prohibited and may be unlawful.

Littlejohn Frazer reserves the right to monitor the content of any
message sent to or from littlejohnfrazer.com and its associate domains,
fmi-litjon.co.uk and litjon.co.uk

A list of partners may be inspected at the above address which is
also the address for serving documents.

Registered to carry on audit work by the Institute of Chartered
Accountants in England & Wales, and authorised and regulated by the
Financial Services Authority for investment business.