首页/文章/ 详情

HyperWork 2024 -二次开发-Tcl语言-Strings(12/12)

13天前浏览537

The task of extracting and manipulating information via a scripting language is often described using the term . Strings are a set of alphanumeric characters stored and manipulated together. These sets are concatenated, truncated, or partitioned by the script with a specific end in mind.

All data items in Tcl, including numeric values, are treated as strings. They are treated as other data types only as needed. This makes string manipulation and the associated commands very important and frequently utilized.

There are a large number of string manipulation commands, as well as pattern and regular expression matching. The following list contains some commonly used string manipulation commands and a summary of their usage. For more in-depth explanations and a complete listing, referred to http://www.tcl.tk/man/ or to a Tcl/Tk handbook.

  • string compare 

  • Compares if two strings are the same. Returns  if equal,  if  is sorted before , and  otherwise.

  •  

  • Returns the length (number of characters) in string.

  • string match 

  • Uses glob-style matching to determine if a  matches . Returns  if it matches,  otherwise.

  • string tolower 

  • Converts  to all lower case.

  • string trim 

  • Trims  characters from both ends of string. If is not specified, it defaults to whitespace.

  • append 

  • Concatenates values ,  etc… onto string.

  • format 

  • Formats , , etc… according to specific format definitions defined by form.

The string length command can be used to check whether a variable has data.

set var1 {};
string length $var1;
0

set var1 "12345";
string length $var1;
5

Similar to string length, string match is used frequently to verify a variable matches a known value. The command takes two arguments, the pattern to search for and the string or variable.

set axis_label "Nodal Acceleration (m/s^2)";
string match "*Acceleration*" $axis_label;
1

set plot_type xy;
string match abc $plot_type;
0

When outputting data to a file or for display purposes, the format command can be used to make sure the values are correctly formatted.

set number "1.234";
format %f $number;
1.234000

format %e $number;
1.234000e+000

format %5.1f $number;
 1.2

format "%-10x%d" Text 100;
Text      100


来源:TodayCAEer
ACT二次开发UM
著作权归作者所有,欢迎分享,未经许可,不得转载
首次发布时间:2024-09-01
最近编辑:13天前
TodayCAEer
本科 签名征集中
获赞 16粉丝 9文章 164课程 0
点赞
收藏
作者推荐

HyperMesh二次开发-谷歌小恐龙轻轻轻轻轻量化版

这是在遇到了电脑暂时无法连接网络的情况想着写下这篇文章。众所周知,谷歌浏览器有个断网后的小游戏,就是那个一致跳不到终点的小恐龙游戏,玩了一会儿遂萌生了用TCL语言实现这个小游戏的想法。游戏界面如图所示。通过按空格键控制字符跳跃,避开黑色方块障碍物。可自定义“小恐龙”,可以输入任意字符来替换跳跃图标,更换字符后,通过ResetGame实现字符的更换。游戏检测到碰撞后会提示游戏结束,可以点击ResetGame按钮重新开始游戏。障碍物会以不同的速度移动,这就是出现残影的原因。启动程序后,通过点击StartGame开始游戏回复关键字“小恐龙”获取下载链接。这里关键就是画布组件。我们可以基于画布组件干很多有意思的事情,比如画图🎨,查看图片,写字,编辑图片,高亮显示元素以提示用户,用于开发安全带插件的时候。canvas的配置功能太多了,就不一一列举,下面是程序用到的canvas说明。#创建游戏画布canvas.qwe.c-width200-height100-bgwhitepack.qwe.c-expandtrue-fillboth#创建文字setdino[.qwe.ccreatetext20$Game::dinoY-text"☻"-font{Arial24}]#创建矩形框setobstacle[.qwe.ccreaterectangle$Game::obstacleX80[expr$Game::obstacleX+20]100-fillblack]#修改坐标.qwe.ccoords$dino20$dinoY来源:TodayCAEer

未登录
还没有评论
课程
培训
服务
行家
VIP会员 学习 福利任务 兑换礼品
下载APP
联系我们
帮助与反馈