MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Data Conversion

  • To: mathgroup at smc.vnet.net
  • Subject: [mg38034] Re: Data Conversion
  • From: Selwyn Hollis <hollisse at mail.armstrong.edu>
  • Date: Tue, 26 Nov 2002 00:50:21 -0500 (EST)
  • References: <arsilf$eed$1@smc.vnet.net>
  • Reply-to: selwynh at earthlink.net
  • Sender: owner-wri-mathgroup at wolfram.com

John,
Here's one approach. I'm assuming that you're starting out with strings.

data1 = {"123-456-7899", "John Smith", "2223334444"};

{l1, l2, l3} = Characters /@ data1;

data2 = Flatten[{
  StringJoin[DeleteCases[#1,"-"]]&/@ Partition[l1, 4],
  StringJoin[#1]&@ l2[[Range@@ Prepend[Flatten[Position[l2," "]]-1, 1]]],
  StringJoin[#1]&@ l2[[Range@@ Append[Flatten[Position[l2," "]]+1, 
Length[l2]]]],
  StringJoin[#1]&/@ {l3[[{1,2,3}]], l3[[{4,5,6}]], l3[[{7,8,9,10}]]}}]

         {"123", "456", "7899", "John", "Smith", "222", "333", "4444"}

data3 = StringJoin[data3 = StringJoin[data2[[Range[1,5]]]],
   StringJoin[Table["0", {24 - Length[Characters[data3]]}]]]

         "1234567899JohnSmith00000"

---
Selwyn Hollis


Moranresearch at aol.com wrote:

>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
>
>





  • Prev by Date: Re: Simplifying expression involving Log and I
  • Next by Date: Re: rightTree[tree[_, _, right_]] := right Hu?
  • Previous by thread: Re: Data Conversion
  • Next by thread: Re: Data Conversion