Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将字节字符串解析为本机scala字节_Scala - Fatal编程技术网

将字节字符串解析为本机scala字节

将字节字符串解析为本机scala字节,scala,Scala,我正试图将这样的字符串解析为列表[字节] 这是绳子 "0x4e 0x01 0x09" 如何从字符串表示中实例化字节?这里有一个使用正则表达式和parseInt的解决方案 def parseBytes(s: String): List[Byte] = (raw"\b0x([0-9a-f]{2})\b".r .findAllMatchIn(s) .map(g => Integer.parseInt(g.group(1), 16).toByte) .toList)

我正试图将这样的字符串解析为
列表[字节]

这是绳子

"0x4e 0x01 0x09"

如何从字符串表示中实例化字节?

这里有一个使用正则表达式和
parseInt
的解决方案

def parseBytes(s: String): List[Byte] =
  (raw"\b0x([0-9a-f]{2})\b".r
    .findAllMatchIn(s)
    .map(g => Integer.parseInt(g.group(1), 16).toByte)
    .toList)
测试:


这里有一个使用正则表达式和
parseInt
的解决方案

def parseBytes(s: String): List[Byte] =
  (raw"\b0x([0-9a-f]{2})\b".r
    .findAllMatchIn(s)
    .map(g => Integer.parseInt(g.group(1), 16).toByte)
    .toList)
测试:


该示例的预期输出是什么?List(0x4e,0x010000000,0x09)这是一个
List[Int]
。您是对的,简化操作以使用其他数据。该示例的预期输出是什么?List(0x4e,0x010000000,0x09)这是一个
List[Int]
。您是对的,简化操作以使用其他数据。