aardio内置函数

今天学习了 Aardio 里的内置常用函数,以后遇到问题应该能更快解决啦!

字符串处理函数

string.len 函数

这个函数就像测量员,能测量字符串的长度。我看了个例子,代码是这样的:

ini 复制代码
import console;
var str = "aardio 真好用";
var length = string.len(str);
console.log("字符串的长度是:", length);
console.pause();
null

这里定义了字符串 str,然后用 string.len 测它的长度,最后输出结果。这就跟用尺子量绳子长度一样简单!

string.replace 函数

它就像修改小能手,能把字符串里的内容替换掉。比如有个例子:

ini 复制代码
import console;
var str = "这个aardio 编程,很强大";
var newStr = string.replace(str, "aardio", "Aardio");
console.log("替换后的字符串是:", newStr);
console.pause();
null

在这个例子里,把字符串里的 "aardio" 都换成了 "Aardio",就像改文章里的错别字。

数学运算函数

math.sqrt 函数

这函数就像开方大师,能算一个数的平方根。比如算面积为 25 的正方形边长,代码如下:

ini 复制代码
import console;
var num = 25;
var result = math.sqrt(num);
console.log(num+"的平方根是:"+result);
console.pause();
null

这里算出 25 的平方根是 5,就像算出了正方形的边长。

math.random 函数

它就像抽奖箱,能生成随机数。例子是这样的:

ini 复制代码
import console;
var randomNum = math.random(1, 10);
console.log("生成的随机数是:"+randomNum);
console.pause();
null

运行代码后,能得到 1 到 10 之间的一个随机数,就像抽奖一样有趣。

习题尝试

今天要定义一个字符串,用 string.replace 把 "hello" 换成 "hi",再生成 1 到 20 之间的随机数并输出。我看了答案代码,好像懂了又好像没完全懂,还得再研究研究。不过我相信多练习,以后肯定能熟练掌握这些函数的!不过经过我的不懈努力下,还是把它拿下了。

答案代码如下:

typescript 复制代码
import console;
import math;

function Replace(){
    var str = "hello aardio"; 
    var newstr = string.replace(str,"he","hi") 
    console.log(newstr)
}

function Rndom_number(){
    number = math.random(1,20)
    console.log(number)
}

Replace()

Rndom_number()

console.pause();
null

虽然今天学得有点晕乎,但我还是挺有收获的,继续加油吧!

相关推荐
RustCoder2 天前
Rust 1.92.0 发布:为 Never 类型铺路,强化调试与安全性
程序员·rust·编程语言
大熊猫侯佩3 天前
Swift 6.2 列传(第十二篇):杨不悔的“临终”不悔与 Isolated Deinit
swift·编程语言·apple
大熊猫侯佩3 天前
深夜的代码惊魂:一个你绝对不能再犯的 Swift 错误
swift·编程语言·apple
大熊猫侯佩3 天前
Swift 6.2 列传(第十一篇):梅若华的执念与“浪子回头”的异步函数
swift·编程语言·apple
HyperAI超神经5 天前
活动回顾丨 北大/清华/Zilliz/MoonBit共话开源,覆盖视频生成/视觉理解/向量数据库/AI原生编程语言
人工智能·ai·开源·编程语言·向量数据库·视频生成·视觉理解
图形学爱好者_Wu6 天前
每日一个C++知识点|原子操作
c++·编程语言
大腾鱼7 天前
Web3 学习:Solidity中的结构体、数组和映射
编程语言
大熊猫侯佩8 天前
Swift 迭代三巨头(下集):Sequence、Collection 与 Iterator 深度狂飙
swift·编程语言·apple
大熊猫侯佩8 天前
Swift 迭代三巨头(中集):Sequence、Collection 与 Iterator 深度狂飙
swift·编程语言·apple
大熊猫侯佩8 天前
Swift 迭代三巨头(上集):Sequence、Collection 与 Iterator 深度狂飙
swift·编程语言·apple