Robot framework 内置库String常用方法

  1. Encode String To Bytes,将字符串(Unicode)编码为字节码(Bytes)。
        | ${bytes} = | Encode String To Bytes | ${string} | UTF-8 |
        | ${bytes} = | Encode String To Bytes | ${string} | ASCII | errors=ignore |

注意:
errors参数控制如果编码某些字符失败了该怎么办。 Python中的encode方法接受的所有值都是有效的,但实际上以下值最有用:

  • strict:如果字符无法编码,则失败(默认)
  • ignore:忽略字符 不能编码
  • replace:替换不能用替换字符编码的字符

2.Decode Bytes To String,使用指定编码,将字节码(Bytes)编码为字符串(Unicode)。

        | ${string} = | Decode Bytes To String | ${bytes} | UTF-8 |
        | ${string} = | Decode Bytes To String | ${bytes} | ASCII | errors=ignore |

3.Remove String,删除指定字符串。

        | ${str} =        | Remove String | Robot Framework | work   |
        | Should Be Equal | ${str}        | Robot Frame     |
        | ${str} =        | Remove String | Robot Framework | o | bt |
        | Should Be Equal | ${str}        | R Framewrk      |

4.测试一下:

代码
结果

5.其他的详见robot.libraries.String源码

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容