JS字符串操作

function str1 ()
{
    var str = "aBcDeFg";
    alert(str.toUpperCase());
    alert(str.toLowerCase());
}
function str2() {
    var box = '123456789';
    alert(box)
    alert("box[1]"+box[1]);
    alert("box.concat('0')"+box.concat('0')); //参数字符串连接
    
    alert("box.slice(4, 6)"+box.slice(4, 6)); //Le
    alert("box.substring(4, 6)"+box.substring(4, 6)); //Le
    alert("box.substr(4,6)" + box.substr(4, 6)); //从第四个开始,选6个
    alert("box.substr(4,2)"+box.substr(4,2)); //Le
    alert("box.slice(4)"+box.slice(4));
    alert("box.substring(4)"+box.substring(4));
    alert("box.substr(4)"+box.substr(4)); //三个都是Lee


}
function str3() {
    var box = 'Mr. Lee is Lee a Lee a Lee';
    alert(box.indexOf('L')); //返回从初始位置搜索L第一次出现的位置,4
    alert(box.lastIndexOf('L')); //返回从末尾位置搜索L第一次出现的位置,11
    alert(box.indexOf('L', 5)); //从第5个位置开始搜索L第一次出现的位置,11
    alert(box.lastIndexOf('L', 5)); //从第5个位置开始向前搜索L第一次出现的位置,4
    alert(box.indexOf(',')); //找不到,返回-1
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值