美文网首页
Robot framework 内置库String常用方法

Robot framework 内置库String常用方法

作者: Zeno00 | 来源:发表于2017-07-24 23:29 被阅读0次
  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源码

相关文章

网友评论

      本文标题:Robot framework 内置库String常用方法

      本文链接:https://www.haomeiwen.com/subject/yhuikxtx.html