Convert String with Split into Hex


what is the best way to convert this string into a HEX?

I do want to have a string-result like this:

28FFF3B39017052C or maybe the 28 FF F3 B3 90 17 05 2C


DSL rules fragment

val String rawdata = ""
val chunks = rawdata.split("\\.")  // escape stop char
val StringBuilder sb = new StringBuilder
chunks.forEach(b | sb.append(Integer::toHexString(Integer::parseInt(b)).toUpperCase + " "))
logInfo("test", "output " + sb)
2020-07-13 02:29:03.256 [INFO ] [.eclipse.smarthome.model.script.test] - output 28 FF F0 88 83 17 4 4E

Nice, it is working well, but how ca I get a leading Zero if b < 10?

Some suggestions here (It’s b< 16 you are interested in)

i’d try the .format() method.
Using a big X in there will replace the toUpperCase as well.

Why did I get this Error?

Configuration model 'wind.rules' has errors, therefore ignoring it: [70,4]: no viable alternative at input 'var' [76,3]: mismatched input ')' expecting 'end'

Part of Rule

		val StringBuilder adr_hex_01 = new StringBuilder
	(b | 
		var val_int = Integer::parseInt(b)
		if (val_int < 16)

You need to use curly braces to denote your multi-line code, like you do with if()

	(b | {
		var val_int = Integer::parseInt(b)

Great, thanks a lot.

Got this error message, why?

val wind_dir_inv = transform("JSONPATH", "$", res)
val wind_spd_inv = transform("JSONPATH", "$", res)
val wind_dir_inv_grad = wind_dir_inv * 22.5
val wind_spd_inv_msec = wind_spd_inv / 10

error msg:

Error during the execution of rule 'rule_get_status': Unknown variable or command '*'; line 231, column 27, length 19

The transform returns a string. Variable wind_dir_inv is a string.

Variable wind_dir_inv is a string. The rules parser does not understand what you mean by '*' here, because you cannot multiply a string.

You already know how to parse a string into a Number.