Message Boards Message Boards

0
|
3343 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:
GROUPS:

Replacing expressions in a list of strings

Posted 11 years ago
pom2 = ToString /@ filesto[[All, {2, 4}]]
out={"{0, 90012}", "{0, 90013}", "{0, 90016}", "{0, 90022}", "{0, \
90034}", "{0, 90042}", "{0, 90102}", "{0, 90106}", "{0, 90115}", "{0, \
90131}", "{0, 90132}", "{0, 90137}", "{0, 90153}", "{0, 90214}", "{0, \
90222}", "{0, 90226}", "{0, 90230}", "{0, 90234}", "{0, 90239}", "{0, \
90247}", "{0, 90304}", "{0, 90306}", "{0, 90312}", "{0, 90316}", "{0, \
90323}", "{0, 90325}", "{0, 90328}", "{0, 90331}", "{0, 90332}", "{0, \
90333}", "{0, 90336}", "{0, 90344}", "{0, 90349}", "{0, 90351}", "{0, \
90354}", "{0, 90358}", "{0, 90408}", "{0, 90413}", "{0, 90416}", "{0, \
90417}", "{0, 90419}", "{0, 90438}", "{0, 90447}", "{0, 90448}", "{0, \
90453}", "{0, 90457}", "{0, 90523}", "{0, 90549}", "{0, 90616}", "{0, \
90618}", "{0, 90638}", "{0, 90640}", "{0, 90642}", "{0, 90649}", "{0, \
90652}", "{0, 90708}", "{0, 90713}", "{0, 90715}", "{0, 50733}"}
Flatten[pom2] /. {lo_ /; (IntegerDigits@ToExpression[lo][[2]])[[1]] ==
9 -> 1,
lo_ /; (IntegerDigits@ToExpression[lo][[2]])[[1]] != 9 -> 2}
This is half-baked target . The thing is to replace -> 1 and 2 by an expression(s) to get the following result:
==9 like that {090012 },{090013},{090016},......and !=9 like {50733}......
Any suggestion are welcome.
Thanks
POSTED BY: Artur Kotarski
2 Replies
This approch uses StringReplace to keep the "0" with the "0, 9" and drop the "0" from the "0, 5"
StringReplace[pom2, {"0, 9" -> "09", "0, 5" -> "5"}]
Posted 11 years ago
Marek,

is this close to what you are trying to do:
 In[1]:= pom2 = {"{0, 90012}", "{0, 90013}", "{0, 90016}",
    "{0, 90022}", "{0, 90034}", "{0, 90042}", "{0, 90102}",
    "{0, 90106}", "{0, 90115}", "{0, 90131}", "{0, 90132}",
    "{0, 90137}", "{0, 90153}", "{0, 90214}", "{0, 90222}",
    "{0, 90226}", "{0, 90230}", "{0, 90234}", "{0, 90239}",
    "{0, 90247}", "{0, 90304}", "{0, 90306}", "{0, 90312}",
    "{0, 90316}", "{0, 90323}", "{0, 90325}", "{0, 90328}",
    "{0, 90331}", "{0, 90332}", "{0, 90333}", "{0, 90336}",
    "{0, 90344}", "{0, 90349}", "{0, 90351}", "{0, 90354}",
   "{0, 90358}", "{0, 90408}", "{0, 90413}", "{0, 90416}",
   "{0, 90417}", "{0, 90419}", "{0, 90438}", "{0, 90447}",
   "{0, 90448}", "{0, 90453}", "{0, 90457}", "{0, 90523}",
   "{0, 90549}", "{0, 90616}", "{0, 90618}", "{0, 90638}",
   "{0, 90640}", "{0, 90642}", "{0, 90649}", "{0, 90652}",
   "{0, 90708}", "{0, 90713}", "{0, 90715}", "{0, 50733}"};

In[2]:= If[(IntegerDigits@ToExpression[#][[2]])[[1]] == 9,
   StringReplace[#, {" " -> "", "," -> ""}],
   StringExpression["{",
    Sequence @@ (ToString /@ (IntegerDigits@ToExpression[#][[2]])),
    "}"]] & /@ pom2

Out[2]= {"{090012}", "{090013}", "{090016}", "{090022}", "{090034}", \
"{090042}", "{090102}", "{090106}", "{090115}", "{090131}", \
"{090132}", "{090137}", "{090153}", "{090214}", "{090222}", \
"{090226}", "{090230}", "{090234}", "{090239}", "{090247}", \
"{090304}", "{090306}", "{090312}", "{090316}", "{090323}", \
"{090325}", "{090328}", "{090331}", "{090332}", "{090333}", \
"{090336}", "{090344}", "{090349}", "{090351}", "{090354}", \
"{090358}", "{090408}", "{090413}", "{090416}", "{090417}", \
"{090419}", "{090438}", "{090447}", "{090448}", "{090453}", \
"{090457}", "{090523}", "{090549}", "{090616}", "{090618}", \
"{090638}", "{090640}", "{090642}", "{090649}", "{090652}", \
"{090708}", "{090713}", "{090715}", "{50733}"}
POSTED BY: Peter Fleck
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract