Re: Data Conversion
- To: mathgroup at smc.vnet.net
- Subject: [mg38030] Re: Data Conversion
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Tue, 26 Nov 2002 00:49:36 -0500 (EST)
- References: <arsilf$eed$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
John,
Here is a long journey to your forms - I am assuming that we start with
{"123-456-7899","John Smith","2223334444"}
and I show input forms to distinguish strings.
(fm1=MapAt[
StringReplace[
StringTake[
ToString[FromDigits/@Split[IntegerDigits[ToExpression[#]]]],
{2,-2}]," " ->""]&,
StringReplace[{"123-456-7899","John Smith","2223334444"},{ "-"->",",
" "->","}],
{-1}])//InputForm
{"123,456,7899", "John,Smith", "222,333,4444"}
(fm2=StringJoin@@
PadRight[
Characters[
StringJoin@@StringReplace[ToLowerCase/@Drop[fm1,-1],","->""]],24,
"0"])//InputForm
"1234567899johnsmith00000"
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
<Moranresearch at aol.com> wrote in message news:arsilf$eed$1 at smc.vnet.net...
>
> I have the following data of the following form.
>
> {123-456-7899, John Smith,2223334444}
>
> How can I convert this to
> {123,456,7899, John,Smith,222,333,4444}
> and then to
>
> {1234567899johnsmith00000)
>
> 1. The "-" are removed
> 2. John Smith is concerted to lower case
> 3. The space between John and Smith is removed (ie john and smith is
> concatenated)
> 4. 123454567899johnsmith is padded right so the the total number of
> characters is 24.
> Thank you.
> John
>