zoukankan      html  css  js  c++  java
  • String 学习与总结

    1.介绍

    String用于字符串操作和验证的测试库,是Robot Framework用于处理字符串的标准库(例如:Replace String Using Regexp, Split To Lines,拆分为行)并验证其内容(例如:Should Be String)。

    以下来自BuiltIn库的关键字也可以用于字符串:

    • Catenate
    • Get Length
    • Length Should Be
    • Should (Not) Be Empty
    • Should (Not) Be Equal (As Strings/Integers/Numbers)
    • Should (Not) Match (Regexp)
    • Should (Not) Contain
    • Should (Not) Start With
    • Should (Not) End With
    • Convert To String
    • Convert To Bytes

    1.keyword 

    Convert To Lowercase/Convert To Uppercase

    用法:[ string ],字符串中字符全转为小写/大写

    结果:

     

    20180515 10:38:25.756 : INFO : ${aa} = AnjnjhDNhdt

    20180515 10:38:25.758 : INFO : ${bb} = anjnjhdnhdt

    20180515 10:38:25.759 : INFO : ${cc} = ANJNJHDNHDT

    Decode Bytes To String(解码)

    用法:[ bytes | encoding | errors=strict ],使用给定的编码将给定字节解码为Unicode字符串。

    参数errors控制解码某些字节失败时该怎么做。 任何在Python中能使用的decode方法在这个关键字中都可以用。

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

    Encode String To Bytes(编码)

    用法:[ string | encoding | errors=strict ]

    Fetch From Left/Fetch From Right

    用法:[ string | marker ],Returns contents of the string before the first occurrence of marker.If the marker is not found, whole string is returned.

    结果:

    ${aa} = aa

    ${bb} = elloeae

    ${cc} = a

    Split String

    用法:[string|separator=None|max_split=-1]返回值为列表,根据分隔符拆分字符串。如果没有给出分隔符,则默认分隔符为任何空格字符串。 在这种情况下,连续的空白以及前后的空白会被忽略。

    如果给出可选的max_split,则字符串最多分隔max_split次,返回的列表将具有max_split + 1个元素。

    其中:aa-->“  An     jnjh DnNh    dt”,cc-->“AnjnjhDnNhdt”

    结果:@{aa} = [ An | jnjh | DnNh | dt ]

              @{bb} = [  A |      j | jh D | Nh    dt ]

              @{cc} = [ A | j | jhD | Nhdt ]

              @{dd} = [ A | j | jhDnNhdt ]

    Split String From Right

    用法:[string|separator=None|max_split=-1],从右侧开始根据分隔符拆分字符串,只有当max_split不是默认值时才会与split string有区别。

    结果:@{aa} = [ A | j | jhD | Nhdt ]

               @{bb} = [ A | j | jhD | Nhdt ]

               @{cc} = [ A | j | jhDnNhdt ]

               @{dd} = [ Anj | jhD | Nhdt ]

    Split String To Characters

    用法:[string],将字符串分割为字符

    结果:@{aa} = [ A | n |   |   | j | n | j | h |   |   | D | n | N | h | d | t ]

    Split To Lines

    用法:[stringstart=0,end=None],将给定字符串拆分为行,行号从0开始,start和end表示返回的起始行和终止行,[start,end)。

    结果:@{aa} = [ aaa | bbbb | cccc | dddd ]

    @{bb} = [ bbbb | cccc | dddd ]

    @{cc} = [ aaa | bbbb | cccc ]

    @{dd} = [ bbbb ]

    @{ee} = [ cccc | dddd ]

    @{ee} = [ aaa ]

    Strip String

    用法:[stringmode=both,characters=None],移除字符串首尾的空格,如果有给出characters,则移除掉字符串首尾中包含在characters中的字符, Please note, that this is not a substring to be removed but a list of characters。

    _表示空格

    结果:${aa} = hello
    ${bb} = hello_
    ${cc} =_hello
    ${ee} = habello
    ${ff} = habelloeaeg

    Generate Random String

    用法:[ length=8 | chars=[LETTERS][NUMBERS] ],根据给定的字符和长度随机产生一个字符串。

    其中,参数chars可以为:

    MarkerExplanation
    [LOWER] Lowercase ASCII characters from a to z.
    [UPPER] Uppercase ASCII characters from A to Z.
    [LETTERS] Lowercase and uppercase ASCII characters.
    [NUMBERS] Numbers from 0 to 9.

    结果:${aa} = mGM113rL

    ${bb} = cwquphbbfkug

    ${cc} = ryzgdaui 

    ${dd} = 25b9

    Get Line

    用法:[ string | line_number ],根据行号,获取字符串中的某一行。行号从0开始。

    结果:${aa} = dd

    ${bb} = dd

    Get Line Count

    用法:[ string ],获取给定字符串的行数。

    Get Lines Containing String

    用法:[ string | pattern | case_insensitive=False ],获取string中包含pattern的所有行,其中pattern为正常的字符串形式。

    Get Lines Matching Pattern

    用法:[ string | pattern | case_insensitive=False ],获取string中匹配pattern的所有行,其中pattern为glob pattern

    The pattern is a glob pattern where:

    * matches everything
    ? matches any single character
    [chars] matches any character inside square brackets (e.g. [abc] matches either ab or c)
    [!chars] matches any character not inside square brackets


    Get Lines Matching Regexp

    用法:[ string | pattern | partial_match=False ],获取string中匹配正则pattern的所有行。

    如果pattern为空,则默认情况下仅匹配空行。当启用部分匹配(partial_match=True)时,空pattern匹配所有行。请注意,要使匹配不区分大小写,您需要在模式前加上不区分大小写的标志(?i)。

    Get Regexp Matches

    [ string | pattern | *groups ]

    Get Substring

    [ string | start | end=None ]

    Remove String

    [ string | *removables ]

    Remove String Using Regexp

    [ string | *patterns ]

    Replace String

    [ string | search_for | replace_with | count=-1 ]

    Replace String Using Regexp

    [ string | pattern | replace_with | count=-1 ]

    Should Be Byte String

    [ item | msg=None ]

    Should Be Lowercase

    [ item | msg=None ]

    Should Be String

    Should Be Titlecase

    Should Be Unicode String

    Should Be Uppercase

    Should Not Be String



  • 相关阅读:
    C++进程通信之命名管道
    从Win32过渡到MFC工程
    Windows常用消息处理与自定义消息
    Windows窗口开发原理(窗口的创建&消息机制)
    _T、_TEXT、TEXT、L的使用记录
    几种多线程同步方式总结
    异步编程之async&await
    rpc理解
    docker 基础namespace cgroup overlayfs network
    python编程书籍资料整理大全
  • 原文地址:https://www.cnblogs.com/ting152/p/12516880.html
Copyright © 2011-2022 走看看