Convert string to specific unicode type

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Convert string to specific unicode type

Post by milkygirl90 » 26 Sep 2021, 21:20

Is it possible to convert to a specific unicode type (say Math Sans Bold or Squared Neg) using ahk?

Example below:

Code: Select all

https://qaz.wtf/u/convert.cgi?text=test+one+two+three

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Convert string to specific unicode type

Post by Rohwedder » 27 Sep 2021, 01:46

Hallo,
try:

Code: Select all

;Math Sans Bold
Text = Test: 0=Zero 9=Nine
Unicode =
Loop, Parse, Text
{
	Asc := Asc(A_LoopField)
	IF Asc between 48 and 57 ;0 and 9
		Unicode .= Chr(120764 + Asc)
	Else IF Asc between 65 and 90 ;A and Z
		Unicode .= Chr(120211 + Asc)
	Else IF Asc between 97 and 122 ;a and z
		Unicode .= Chr(120205 + Asc)
	Else
		Unicode .= A_LoopField
}
MsgBox,% Unicode

User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Convert string to specific unicode type

Post by milkygirl90 » 27 Sep 2021, 03:21

very cool. may I know how you decided on the code to use for math sans bold, as I would like to try it myself for the other unicodes too (like squared neg)?

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Convert string to specific unicode type

Post by Rohwedder » 27 Sep 2021, 03:54

I have hereby analyzed the results of your page:

Code: Select all

q::
Send, ^c
Sleep, 100
ToolTip,% Ord(ClipBoard)
Return ;Returns the ordinal value (numeric character code) of the first character

User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Convert string to specific unicode type

Post by milkygirl90 » 27 Sep 2021, 04:09

I tested it and math sans bold comes up as such:

Code: Select all

https://i.imgur.com/Lws8kYP.png
but I don't see it anywhere in your code (tried adding/subtracting but also didn't get anywhere near that number). Do you mind sharing how to use it? Thanks!

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Convert string to specific unicode type

Post by Rohwedder » 27 Sep 2021, 04:27

https://qaz.wtf/u/convert.cgi?text=AZaz09
The tooltip shows the ordinal value
Image
Attachments
grafik.png
grafik.png (2.39 KiB) Viewed 657 times

User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Convert string to specific unicode type

Post by milkygirl90 » 27 Sep 2021, 04:32

hmm what I meant was the number in the tooltip is not in your original code below

Code: Select all

;Math Sans Bold
Text = Test: 0=Zero 9=Nine
Unicode =
Loop, Parse, Text
{
	Asc := Asc(A_LoopField)
	IF Asc between 48 and 57 ;0 and 9
		Unicode .= Chr(120764 + Asc) ;120302 not found anywhere here, so how do we use it after getting the number from tooltip?
	Else IF Asc between 65 and 90 ;A and Z
		Unicode .= Chr(120211 + Asc)
	Else IF Asc between 97 and 122 ;a and z
		Unicode .= Chr(120205 + Asc)
	Else
		Unicode .= A_LoopField
}
MsgBox,% Unicode



and my number is different from yours, even though both are highlighting the math sans bold:
Image

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Convert string to specific unicode type

Post by Rohwedder » 27 Sep 2021, 04:53

The differences of the ordinal value between ASCII characters and Unicode Math sans bold are:
120205 for lowercase, 120211 for uppercase, and 120764 for numerals.

Post Reply

Return to “Ask for Help (v1)”