字符串截取

chapter_3_4-1.awk

BEGIN{
}
{
    content = "this is a test";
    chinese = "这是字符串截取测试";

    print(substr(content, 9));
    print(substr(content, 6, 4));
    print(substr(chinese, 3));
    print(substr(chinese, 3, 1000));
}
END{
}

$echo ""|awk -f chapter_3_4-1.awk
a test
is a
字符串截取测试
字符串截取测试

subsr()用于从字符串中指定位置和长度截取出子串,函数原型:

substr(s, i [, n])
s 待截取的字符串
i 索引位置,从1开始,按照字符计算、非字节
n 要截取的长度,默认或者填写长度超出字符尾,则截取到字符尾

results matching ""

    No results matching ""