[R] Obtain the hex code for a given character --- thanks.

David Winsemius dwinsemius at comcast.net
Wed Feb 5 21:17:26 CET 2014


On Feb 5, 2014, at 12:53 AM, Rolf Turner wrote:

> 
> 
> And the winner is ....... (drum roll) ....... DAVID WINSEMIUS!!!
> 
> Thank you hugely David.  You have completely solved my problem.
> The last bit with format.hexmode() so as to get "00A3" rather than
> just "a3" was actually unnecessary; I could've lived with "a3".  But it was a nice bit of polish.
> 
> How you manage to find the relevant functions in the bewildering (to me) superabundance of functions is impressive as well as astonishing.

I have in the past found `as.hexmode` (which I learned after needing as.octmode as part of my efforts to understand plotmath and using symbol fonts) to be very useful so I did not need to do anything more than "?as.hexmode". I got to the help page for `utf8ToInt` by way of the links on the ?Encodings page. I can never remember the names of all these functions either. I just follow links in the help system until I get what I need.

-- 
David.

> 
> Thanks again.
> 
> cheers,
> 
> Rolf
> 
> On 05/02/14 19:07, David Winsemius wrote:
>> 
>> On Feb 4, 2014, at 8:56 PM, David Winsemius wrote:
>> 
>>> 
>>> On Feb 4, 2014, at 4:57 PM, Rolf Turner wrote:
>>> 
>>>> 
>>>> 
>>>> If I have a character such as "£" stored in a object called "xxx", how can I obtain the hex code representation of this character?  In this case I know that the hex code is "\u00A3", but if I didn't, how would I find out?
>>>> 
>>>> I would like a function "foo()" such that foo(xxx) would return, say, the string "00A3".
>>>> 
>>> 
>>> Close:
>>> 
>>>> as.hexmode(utf8ToInt("£"))
>>> [1] "a3"
>>> 
>> 
>> Looking at the help page again I realized that there was a `format.hexmode` to deliver as requested:
>> 
>>> format(as.hexmode(utf8ToInt("£")), width=4, upper=TRUE)
>> [1] "00A3"
>> 
> 

David Winsemius
Alameda, CA, USA




More information about the R-help mailing list