Quantcast

codePointToNum

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

codePointToNum

prothero--- via use-livecode
So, if I do something like this:

*put the codePointToNum("§")*

I will get the Unicode address of that character as a Decimal number.

How can I get it as a Hex number?

Richmond.
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: codePointToNum

prothero--- via use-livecode
On 2017-03-31 12:12, Richmond via use-livecode wrote:
> So, if I do something like this:
>
> *put the codePointToNum("§")*
>
> I will get the Unicode address of that character as a Decimal number.
>
> How can I get it as a Hex number?

Two options - you can use baseConvert:

   put baseConvert(10, 16, codepointToNum("§")

or you can use format:

   put format("%x", codepointToNum("§"))

The latter is much more flexible e.g.:

   put format("\\u{%06x}", codepointToNum("§"))

Gives the codepoint as the escape sequence for JSON strings (for
example).

Warmest Regards,

Mark.

--
Mark Waddingham ~ [hidden email] ~ http://www.livecode.com/
LiveCode: Everyone can create apps

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: codePointToNum

prothero--- via use-livecode
Thanks for a very prompt and useful reply!

Richmond.

On 31/03/17 13:33, Mark Waddingham via use-livecode wrote:

> On 2017-03-31 12:12, Richmond via use-livecode wrote:
>> So, if I do something like this:
>>
>> *put the codePointToNum("§")*
>>
>> I will get the Unicode address of that character as a Decimal number.
>>
>> How can I get it as a Hex number?
>
> Two options - you can use baseConvert:
>
>   put baseConvert(10, 16, codepointToNum("§")
>
> or you can use format:
>
>   put format("%x", codepointToNum("§"))
>
> The latter is much more flexible e.g.:
>
>   put format("\\u{%06x}", codepointToNum("§"))
>
> Gives the codepoint as the escape sequence for JSON strings (for
> example).
>
> Warmest Regards,
>
> Mark.
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: codePointToNum

prothero--- via use-livecode
In reply to this post by prothero--- via use-livecode
However, "(baseConvert: bad destination base)" does not help much.

This mainly because your example was wrong.

I tried this:

put baseConvert(codePointToNum("&"), 10, 16)  because your syntax was
the wrong way round,

BUT it go "all stuffy" about the codePointToum, so I did this:

put codePointToNum("&") into NUMM
put baseConvert(NUMM, 10, 16)

and got the number.

Richmond.

On 3/31/17 1:33 pm, Mark Waddingham via use-livecode wrote:

> On 2017-03-31 12:12, Richmond via use-livecode wrote:
>> So, if I do something like this:
>>
>> *put the codePointToNum("§")*
>>
>> I will get the Unicode address of that character as a Decimal number.
>>
>> How can I get it as a Hex number?
>
> Two options - you can use baseConvert:
>
>   put baseConvert(10, 16, codepointToNum("§")
>
> or you can use format:
>
>   put format("%x", codepointToNum("§"))
>
> The latter is much more flexible e.g.:
>
>   put format("\\u{%06x}", codepointToNum("§"))
>
> Gives the codepoint as the escape sequence for JSON strings (for
> example).
>
> Warmest Regards,
>
> Mark.
>

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: codePointToNum

prothero--- via use-livecode
On Sat, Apr 1, 2017 at 4:11 AM, Richmond Mathewson via use-livecode
<[hidden email]> wrote:

> put baseConvert(codePointToNum("&"), 10, 16)
>
> BUT it go "all stuffy" about the codePointToum, so I did this:
>
> put codePointToNum("&") into NUMM
> put baseConvert(NUMM, 10, 16)
>

On my Mac 10.11.6 using LC 9.0.0 dp4 both of those code snippets
produce '26' in an egalitarian manner.

There should be no reason why:

 put baseConvert(codePointToNum("&"), 10, 16)

should make your computer "all stuffy". If it is then there is a bug to report.

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Loading...