首页 > 其他分享 >String

String

时间:2023-04-08 11:44:41浏览次数:27  
标签:trim console String 索引 str 字符串 log

创建方式

image

属性

lenth

方法

  • charAt() : 获取指定位置的字符
  • indexOf() : 检索字符串
  • trim() : 去除字符串左右两侧空格
  • substring(start,end) --- 开始索引,结束索引(含头不含尾)

<script>

  //创建字符串对象
  var str= new String("hello");
  console.log(str);
  var str2 ="  hello2 string  ";
  console.log(str2);

  //属性
  //长度
  console.log(str.length);

  //方法:
  //charAt:获取指定位置的字符
  console.log(str.charAt(4));

  //indexOf:检索字符串
  console.log(str.indexOf("lo"));

  //trim:去除字符串左右两侧空格
 var s=  str2.trim();
  console.log(s);

  //substring(start,end) --- 开始索引,结束索引(含头不含尾)
  console.log(str.substring(0,2))

</script>

标签:trim,console,String,索引,str,字符串,log
From: https://www.cnblogs.com/CenCen/p/17298250.html

相关文章

  • C++竞赛常用函数库stl快捷查询手册(vector,map,set,queue,string等)
    1.控制输出流<iomanip>;cout<<setprecision(<span="">int);保留int位有效数字cout<<setprecision(<span="">int)<<fixed;保留int位有效小数为不足4位数的数填充0(如1填充变成0001),cout<<setfill('0')<<setw(4)(一次性效果)......
  • js String汇总
    //----------JavaScriptString----------//charAtcharCodeAt//concatrepeatsplit//slicesubstring//replacereplaceAll//toLowerCasetoUpperCase//startsWithendsWith//indexOflastIndexOfincludes//matchsearch//charAt()//返回在指定位......
  • StringToByte(char* source, uint8_t* dest, int sourceLen)
    voidStringToByte(char*source,uint8_t*dest,intsourceLen){inti;uint8_thighByte,lowByte;for(i=0;i<sourceLen;i+=2){highByte=toupper(source[i]);lowByte=toupper(source[i+1]);if(highB......
  • PrintDocument DrawString C# 换行问题
    在使用80mm小票机做再次开发时使用DrawString无法自动换行导致文字被截断终于找到解决方案:别忘了给我点赞,留言源代码如下:立跑可用 链接:https://pan.baidu.com/s/1vywMUvGXMaFh_1o7ywDQTA?pwd=yyyy提取码:yyyy......
  • String split 坑 防止空 str.split(",")和str.split(",",-1)的区别
    str.split(",",-1);  packagecom.example;publicclassSplitTest{  publicstaticvoidmain(String[]args){    /**     *1.如果字符串最后一位有值,则没有区别,2.如果最后n位都是切割符,split("")不会继续切分,split("",-1)会继续切分......
  • 【segmentation fault】std::string析构崩溃
    今天写了一个小工具,运行时发生segmentationfault,现象如下第一步:review崩溃附近代码,产生疑惑,崩溃的地方居然是变量定义的地方std::stringaccessToken;崩溃在这个地方,我直接懵了,只是变量定义为啥会报错,没有任何思路,打算单步调试。第二步:单步调试代码,发现并且是定义的时候崩......
  • WPF的控件字符串内容使用StringFormat进行字符串转换
    在WPF中TextBlock的Text有时内容只需要改变个别数字,而不需要所以内容都修改,这时候就要使用StringFormat, 如:<TextBlockText="Ihavexxxfriends"/>这里面的xxx是个变量,那在Binding时应该怎样写呢<TextBlockText="{BindingFirendNumber,StringFormat='Ihave{0}firends......
  • c++ string类的字符在内存的储存位置
    1.数据<=16字节,在当前栈区#include<iostream>#include<stdio.h>#include<stdlib.h>usingnamespacestd;intmain(){stringtemp="123456789012345";//注意长度int*a=(int*)malloc(sizeof(int));intb=0;for(a......
  • c++ std::string_view
    std::string_view系C++17标准发布后新增的内容。C++17中我们可以使用std::string_view来获取一个字符串的视图,字符串视图并不真正的创建或者拷贝字符串,而只是拥有一个字符串的查看功能。std::string_view比std::string的性能要高很多,因为每个std::string都独自拥有一份字符串的拷......
  • java -- Stringbuild、Date和Calendar类
    Stringbuild类由于String类的对象内容不可改变,每次拼接都会构建一个新的String对象,既耗时,又浪费内存空间这时需要通过java提供的StringBuild类解决这个问题StringBuilder又称为可变字符序列,它是一个类似于String的字符串缓冲区,可以看作是一个容器,容器中可以装很多字符串可......