Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1104153
  • 博文数量: 121
  • 博客积分: 8910
  • 博客等级: 上将
  • 技术积分: 2915
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-18 09:36
文章分类

全部博文(121)

文章存档

2011年(3)

2010年(100)

2008年(18)

分类: BSD

2008-06-06 15:45:20

################
# studykommander
################
#####
# 第1页
#####
数组的使用   2008-06-6 11:24

例程:Arrays.kmdr

一、数组的初始化

数组由三个部分组成,分别是数组名,数组键值,和数组元素值

Arrays.kmdr在form初始化中定义了数组并进行赋值:

@Array.setValue(Programs, kcalc, KDE calculator)
@Array.setValue(Programs, kwrite, Advanced editor)
@Array.setValue(Programs, ark, Archive tool)
@Array.setValue(Programs, kdict, Interface to online dictonaries)

用到的函数是Array里面的setValue,参数按顺序分别是:

数组名:Programs
数组键:kcalc
元素值:KDE calculator

二、引用数组值

@Array.value(Programs, @ListBox1)

@ListBox1 指的是 从ListBox1 中返回的 @selectWidgetText ,实际上就是键值。

正确引用数组值的方法是:

@Array.Value(数组名,键值)

三、遍历数组元素

@Array.keys(Programs)          返回数组所有key的列表

@Array.values(Programs)          返回数组所有元素值的列表

四、其他操作

@Array.count(Programs)          返回数组元素个数

@Array.remove(Programs, kwrite)    删除指定数组key的数组元素

@Array.fromString(Programs, kwrite\tA simple edit\n)   从字符串中添加元素,格式如示例。

@Array.toString(Programs)       把数组元素转换为字符串,格式key/tvalue/n


以上就是数组的所有操作,这些操作都是由kommander的数组模块提供的。




#####
# 第2页
#####
Kommander的字符串操作

一、Kommander所支持的字符串操作:

计算字符串长度:@String.length(字符串)

字符串截取: @String.left(),@String.right(),@String.mid(),@String.remove(),@String.replace()

字符串大小写转换:@String.upper(),@String.lower()

测试字符串:@String.isNumber(),@String.isEmpty()

字符串操作:@String.contains(),@String.find(),@String.compare()

-lt   0      ;小于零
-gt  0      ;大于零
-eq  0      ;等于零


二、示例:String.kdmr,演示字符串的各种操作。

textedit1的population动作,它与执行按钮进行了帮定,触发对lineEdit内容的处理。lineEdit的kmdr为@widgetText。

@Array.setValue(Bool, 1, yes)
@Array.setValue(Bool, 0, no)

定义数组Bool,因为kommander不支持逻辑数据类型。

从示例分析来看,kommander继承了kde类中的支持html标签功能

Kommander string functions

   


Length: @String.length("@LineEdit1")
                                       测试字符串长度

First 5 chars: @String.left("@LineEdit1", 5)
                                取字符串前5个字符

Last 5 chars: @String.right("@LineEdit1", 5)
                              取字符串后5个字符,不包括字符串结束标志

Chars from 6th to 10th: @String.mid("@LineEdit1", 6, 5)
           从字符串的第六个字符开始,取中间的五个字符。

Remove spaces: @String.remove("@LineEdit1", " ")
                   移出字符串中的空格

Replace spaces with *: @String.replace("@LineEdit1", " ", *)
      用*替换字符串中的空格

Uppercase: @String.upper("@LineEdit1")
                                   把字符串转换为大写

Lowercase: @String.lower("@LineEdit1")
                                    把字符串转换为小写

Is a number?: @Array.value(Bool, @String.isNumber("@LineEdit1"))
    测试是否为数字

Is empty? @Array.value(Bool, @String.isEmpty("@LineEdit1"))
            测试是否为空

Contains "Kommander"?: @String.contains("@LineEdit1", "Kommander")
    测试包含,如果真返回1

Position of "Kommander": @String.find("@LineEdit1", "Kommander")
          查找指定字符串,返回具体位置。

Compare with "Kommander":
@execBegin
if [ @String.compare("@LineEdit1", "Kommander") -lt 0 ];then
    echo "Less than Kommander
"

elif [ @String.compare("@LineEdit1", "Kommander") -gt 0 ];then
    echo "Greater than Kommander
"

elif [ @String.compare("@LineEdit1", "Kommander") -eq 0 ];then
    echo "Equals Kommander
"

fi
@execEnd
Case insensitive match with "Kommander":
@execBegin
if [ @String.compare(@String.lower("@LineEdit1"), "kommander") -eq 0 ];then
    echo "Match found
"

else
    echo "Match failed
"

fi
@execEnd

一些知识点:

1、@execBegin    @execEnd    这两个指令把其中的指令定义为一个逻辑代码块。

2、条件分支语句

if [   条件表达式   ];then

elif [   条件表达式   ];then

fi


执行结果:






阅读(2643) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~