MathGroup Archive 2002

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

Search the Archive

Re: Data Conversion

  • To: mathgroup at smc.vnet.net
  • Subject: [mg38068] Re: [mg38006] Data Conversion
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Thu, 28 Nov 2002 14:09:46 -0500 (EST)
  • References: <200211250657.BAA14617@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

If I understood you correctly, this may do what you want:

In[1]:=
st1 = ToString /@ {"123-456-7899", John Smith, 2223334444}
Out[1]=
{123-456-7899,John Smith,2223334444}

In[2]:=
st2 = ToString[{StringReplace[st[[1]], "-" -> ","], 
    StringReplace[st[[2]], " " -> ","], 
    StringTake[st[[3]], 3], StringTake[st[[3]], {4, 6}], 
    StringTake[st[[3]], {7, 10}]}]
Out[2]=
{123,456,7899, John,Smith, 222, 333, 4444}

In[3]:=
Head[st2]
Out[3]=
String

In[4]:=
st3 = StringTake[ToLowerCase[StringReplace[ToString[st2], 
     {" " -> "", "," -> ""}]], {2, 25}]
Out[4]=
1234567899johnsmith22233

In[5]:=
pad = Last[Position[Table[DigitQ[StringTake[st3, {j}]], 
      {j, -1, -14, -1}], True]][[1]]
Out[5]=
5

In[7]:=
StringReplacePart[st3, StringTake["00000000000000000", 
   pad], {24 - pad+1, 24}]
Out[7]=
1234567899johnsmith00000

Tomas Garza
Mexico City

----- Original Message ----- 
From: <Moranresearch at aol.com>
To: mathgroup at smc.vnet.net
Subject: [mg38068] [mg38006] Data Conversion


> 
> 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: Limits to zooming graphics in 4.2 ?
  • Next by Date: Find all complex root in a region
  • Previous by thread: Data Conversion
  • Next by thread: Re: Data Conversion