Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Got a tip ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97850] Re: [mg97843] Got a tip ?
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Tue, 24 Mar 2009 05:28:10 -0500 (EST)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200903230905.EAA27168@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

If you're willing to allow your inputs to be one-character strings:

   alf="abcdefghijklmnopqrstuvwxyz";
   f[ltr_]:= First@First@StringPosition[alf,ltr]

   f["b"]
2

If you _really_ want plain, unadorned single-letter symbols as inputs, 
replace alf above by

   alf=ToExpression@Characters[alf]
   g[char_] := First@First@Position[letters, char]

   g[b]
2


Fabrizio wrote:
> Hello,
> 
> I want to write a function that translates its argument (which is a letter of the alphabet) into a numerical value.
> 
> f[a] = 1
> f[b] = 2
>  
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • References:
  • Prev by Date: Re: Got a tip ?
  • Next by Date: Re: Question about how to graph the vector field for the differential
  • Previous by thread: Re: Got a tip ?
  • Next by thread: Re: Got a tip ?