Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: position of letters in a string

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53848] Re: [mg53803] position of letters in a string
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sat, 29 Jan 2005 06:03:02 -0500 (EST)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

UnsortedUnion[x_]:=
  Module[{f},f[y_]:=
      (f[y]=Sequence[];y);
    f/@x]; (* From Further Examples for Union  *)

relPositions[str_String] :=
    Module[{chars=UnsortedUnion[Characters[str]]},
      ToExpression[#[[1]] <> "=" <>
              ToString[#[[2]]]]& /@
        Thread[{chars,Range[Length[chars]]}]];

lst={"catcatz","zrzttys"};

relPositions[lst[[1]]];

{c,a,t,z}

{1,2,3,4}

relPositions[lst[[2]]];

{z,r,t,y,s}

{1,2,3,4,5}


Bob Hanlon

> 
> From: zak <chocolatez at gmail.com>
To: mathgroup at smc.vnet.net
> Date: 2005/01/28 Fri AM 02:43:47 EST
> To: mathgroup at smc.vnet.net
> Subject: [mg53848] [mg53803] position of letters in a string
> 
> in the list of strings:
> lst={"catcatz","zrzttys"}
> i want some procedure to give the letters in every string a number
> depending on its position and discarding the recurrent letters such
> that:
> first string: c=1;  a=2;  t=3; z=4
> second string: z=1;  r=2;  t=3;  y=4;  s=5
> zak
> 
> 


  • Prev by Date: Re: position of letters in a string
  • Next by Date: Re: random matrix from row and column sums
  • Previous by thread: Re: position of letters in a string
  • Next by thread: Nonlinear Curve Fitting