Raw hex value of a string

lovexylitol

New Member
Reaction score
2
Is there a way to obtain the raw hex value of a string.(or char) Not a workaround but a direct method so it will work on unicode strings.

I have tried the following code but didnt work.(and is specified that it does not work in the jass manual)

JASS:

function String2Int takes string s returns integer
    return s
    return 0
endfunction


Thanks! :thup:
 

CaptDeath

New Member
Reaction score
103
there is a jass help section so it should be
this is for gui while jass help is for ... jass
 

Flare

Stops copies me!
Reaction score
662
Not particularly sure if it's possible, but I don't think casting a string to integer like that would work (I recall seeing that it could cause crashes if the string couldn't be cast to an integer)

there is a jass help section so it should be
this is for gui while jass help is for ... jass

Well, this isn't specifically asking for help in JASS, just something more technical than what's normally asked for, and main WEHZ is for World Editor related stuff, not just GUI...
 

Builder Bob

Live free or don't
Reaction score
249
maybe this Base16 library can help. It can be modified to do other character sets.
Requires JassNewGen Editor

JASS:
library Base16

globals
	private constant string CHARS = "0123456789ABCDEF"
	private constant integer BASE = StringLength(CHARS) //16
endglobals

function ToHex takes integer n returns string
	return SubString(CHARS, n, n + 1)
endfunction

function Dec2Hex takes integer dec returns string
	local integer r = ModuloInteger(dec, BASE)
	if dec - r == 0 then
		return ToHex(r)
	else
		return Dec2Hex((dec - r) / BASE) + ToHex(r)
	endif
	return ""
endfunction

function ToDec takes string s returns integer
	local integer n = 0
	local string hex
	loop
		exitwhen(n == BASE)
		if SubString(CHARS, n, n + 1) == s then
			return n
		endif
		set n = n + 1
	endloop
	return 0
endfunction

function Hex2Dec takes string hex returns integer
	local integer length = StringLength(hex)
	if length == 1 then
		return ToDec(hex)
	elseif length > 1 then
		return Hex2Dec(SubString(hex, 0, length - 1)) * BASE + ToDec(SubString(hex, length - 1, length))
	endif
	return 0
endfunction

endlibrary
 

SFilip

Gone but not forgotten
Reaction score
634

lovexylitol

New Member
Reaction score
2
First of all, thanks for the reply!

Hmmm.. the important part was >> unicode << meaning korean japanese etc.
The functions above are actually workarounds as I mentioned : they do not get the hex value, but compair the input to a pre-defined value(string in these cases) to obtain a hex value. It works fine on english, but is (almost) impossible to implement on korean or japanese.

To be more specific, some examples.

Function : StringToByteArray(String input)
Returns : Byte representation of input as unicode (In string or int or whatever format)

Example : StringToByteArray("Unicode!")
Return : & # 85 ; & # 110 ; & # 105 ; & # 99 ; & # 111 ; & # 100 ; & # 101 ; & # 33 ; (Unicode representation of "Unicode!")
Example2 : StringToByteArray("한글")
Return2 : & # 54620; & # 44544;

(Just in case, those &#; are not really important, the data is what I want)

Well, since I couldnt find any functions that does something like this in the basic blizzard .j files, I dont really except this to be possible. But I'm new to the world of jass, and somebody might know a trick.
 

saw792

Is known to say things. That is all.
Reaction score
280
I think the only way you could actually do that would be to have a list (multiple arrays, or extended arrays) of every single character and their corresponding code. Which is quite ridiculous.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top