[Date Index]
[Thread Index]
[Author Index]
Re: Part or Partition or Split or Extract or ...... ????
*To*: mathgroup at smc.vnet.net
*Subject*: [mg85425] Re: Part or Partition or Split or Extract or ...... ????
*From*: yatesd at mac.com
*Date*: Sun, 10 Feb 2008 05:15:14 -0500 (EST)
*References*: <fojrtu$h1k$1@smc.vnet.net>
I assume that your Import has resulted in A being a matrix of strings.
To check this try InputForm[ A[[1]] ] and see if there are quotes
around the items. If this is the case, then you could try something
like this (where the output shown here is in InputForm. The standard
output does not show quote characters and represents backslashes
differently.)
I have assumed A looks something like this:
{{"(300a,011c) DS[25\55] # 6", "2", " unknownparameter"},
{"(300a,011c) DS[0\60] # 4", "2", " unknownparameter"},
{"(300a,011c)
DS[64.5\64.5\64.5\64.5\64.5\64.5\64.5\64.5\64.5\64.5\64.5\64.5\
\64.5\6]... # 400", "80", " unknownparameter"}}
where I added the closing ] in the third item so as to make the code
work.
step1 = StringCases[#, "DS[" ~~ nums : __ ~~ "]" :> nums] & /@ A[[All,
1]]
so step1 should result in something like
{{"25\\55"}, {"0\\60"},{"64.5\\64.5\\64.5\\64.5\\64.5\\64.5\\64.5\
\64.5\\64.5\\64.5\\64.5\\\64.5 \\64.5\\6"}}
(Note the the backslash (\) has a special meaning in Mathematica and
so when you want to represent the string character, you need to use "\
\"
step2 = StringSplit[#, "\\"] & @@@ step1
which should result in something like this
{{"25", "55"}, {"0", "60"}, {"64.5", "64.5", "64.5", "64.5", "64.5",
"64.5", "64.5", "64.5", "64.5", "64.5", "64.5", "64.5 ", "64.5","6"}}
now convert the strings to numbers via something like
step3 = step2 /. x_String :> ToExpression[x]
and step3 should result in something like
{{25, 55}, {0, 60}, {64.5, 64.5, 64.5, 64.5, 64.5, 64.5, 64.5, 64.5,
64.5, 64.5, 64.5, 64.5, 64.5, 6}}
where the entries are now numbers
Now you can manipulate the numbers as needed (which I am afraid I did
not fully understand from your posting).
Hope that helps,
Derek
Prev by Date:
**Re: Part or Partition or Split or Extract or ...... ????**
Next by Date:
**Re: button to load files from a window**
Previous by thread:
**Re: Bug Report for DiscreteMath`Combinatorica`Contract**
Next by thread:
**Re: Part or Partition or Split or Extract or ...... ????**
| |