将文本转换为字节
将文本转换为字节列表。
脚本语法
IBM RPA 的专有脚本语言的语法与其他编程语言类似。 该脚本语法在脚本文件中定义命令的语法。 您可以在 IBM RPA Studio的 脚本 方式下使用此语法。
textToBytes --text(String) --encoding(EncodingType) (Boolean)=success (List<Byte>)=value
输入参数
下表显示了此命令中提供的输入参数的列表。 在表中,您可以看到在 IBM RPA Studio的脚本方式及其 Designer 方式等效标签中工作时的参数名称。
| 设计器方式标签 | 脚本方式名称 | 必需的 | 接受的变量类型 | 描述 |
|---|---|---|---|---|
| 文本 | text |
Required |
Text |
要转换为字节列表的文本。 |
| 编码 | encoding |
Required |
EncodingType |
文本编码格式。 请参阅 encoding 参数选项 以获取详细信息。 |
encoding 参数选项
下表显示可用于 encoding 参数选项的选项。 该表显示了在脚本方式下工作时的可用选项以及在设计器方式下的等效标签。
| 设计器方式标签 | 脚本方式名称 |
|---|---|
| 操作系统缺省值 | Default |
| UTF8 | UTF8 |
| UTF7 | UTF7 |
| UTF32 | UTF32 |
| Unicode | Unicode |
| ASCII | ASCII |
| 大尾数法 Unicode | BigEndianUnicode |
输出参数
| 设计器方式标签 | 脚本方式名称 | 接受的变量类型 | 描述 |
|---|---|---|---|
| 成功 | succeess |
Boolean |
如果文本转换成功,那么返回 True ; 否则返回 False。 |
| 字节列表 | value |
List <Byte> |
返回为 Text 参数中指定的每个文本字符生成的字节列表。 |
示例
转换文本 " 量子计算是一种计算类型,其运算可以驾驭量子力学的现象。 转换为字节,并分别返回文本中每个字符的字节列表。
defVar --name textToConvert --type String --value "Quantum computing is a type of computation whose operations can harness the phenomena of quantum mechanics."
defVar --name byteList --type List --innertype Byte
textToBytes --text "${textToConvert}" --encoding "UTF8" byteList=value
logMessage --message "Text: ${textToConvert}\r\n Text length to be converted: ${textToConvert.Length}\r\n List of Bytes Generated:${byteList}\r\n" --type "Info"
// Return the following output in the console:
// Text: Quantum computing is a type of computation whose operations can harness the phenomena of quantum mechanics.
// Length of text to be converted: 107
// List of Bytes Generated: [81,117,97,110,116,117,109,32,99,111,109,112,117,116,105,110,103,32,105,115,32,97,32,116,121,112,101,32,111,102,32,99,111,109,112,117,116,97,116,105,111,110,32,119,104,111,115,101,32,111,112,101,114,97,116,105,111,110,115,32,99,97,110,32,104,97,114,110,101,115,115,32,116,104,101,32,112,104,101,110,111,109,101,110,97,32,111,102,32,113,117,97,110,116,117,109,32,109,101,99,104,97,110,105,99,115,46]