Bash字符串处理(与Java对照) - 26.根据位置和长度截取子串

Bash字符串处理(与Java对照) - 26.根据位置和长度截取子串

In Java

String.substring

String     substring(int beginIndex)
          返回一个新的字符串,它是此字符串的一个子字符串。
 String     substring(int beginIndex, int endIndex)
          返回一个新字符串,它是此字符串的一个子字符串。

 

In Bash

Bash内置的取子串功能

取指定位置开始到串尾的子串,INDEX从0开始算。

${STR:$INDEX}

取指定位置开始、指定长度的子串

${STR:$INDEX:$LENGTH}

与Java不同的是,LENGTH可以大于串的长度。

 

[root@jfht ~]# STR=Hello
[root@jfht ~]# echo ${STR:3}
lo
[root@jfht ~]# echo ${STR:1:2}
el

[root@jfht ~]# echo ${STR:2:10}
llo

 

另外, INDEX还可以是负数,意思是从尾部倒数的位置开始。

但是要注意INDEX的写法,加上小括号,或者在前面加空格或0。

[root@jfht ~]# STR=Hello
[root@jfht ~]# echo ${STR:(-2)}
lo
[root@jfht ~]# echo ${STR:(-3)}
llo
[root@jfht ~]# echo ${STR:-3} 
Hello

-3没有加小括号或前面加空格,就会产生问题。

[root@jfht ~]# echo ${STR: -3}  
llo
[root@jfht ~]# echo ${STR:(-3):2}
ll

[root@jfht ~]# STR=123456789

有文章说也可以在前面加0,试了一下果然可以。
[root@jfht ~]# echo ${STR:0-4}
6789
[root@jfht ~]# echo ${STR:0-4:3}
678

 

补充对${STR:-3}的说明。

man bash 写道
${parameter:-word}
    Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise,
the value of parameter is substituted.

 

使用expr substr取子串

另外也有用expr来取子串的,但效率不如上面。

expr substr "$STR" "$POS" "$LENGTH"

注意:POS从1开始。

man expr 写道
substr STRING POS LENGTH
    substring of STRING, POS counted from 1
 

[root@jfht ~]# STR=Hello

[root@jfht ~]# expr substr "$STR" 2
expr: 语法错误
[root@jfht ~]# expr substr "$STR" 2 1
e
[root@jfht ~]# expr substr "$STR" 2 3
ell
[root@jfht ~]# expr substr "$STR" 2 10
ello

 

使用expr正则表达式匹配功能也可以实现取子串,不过有点杀鸡用牛刀了。

[root@jfht ~]# STR=123456789
[root@jfht ~]# POS=3
[root@jfht ~]# LEN=4
[root@jfht ~]# expr match "$STR" ".\{$POS\}\(.\{$LEN\}\).*"
4567

 

用cut命令截取子串

用cut命令也可以进行字符串截取。

echo "$STR" | cut -c$START-$END

截取STR串中从START开始到END结束的子串,位置从1开始计数。

echo "$STR" | cut -c$START-

截取STR串中从START开始到末尾的子串。

echo "$STR" | cut -c-$END

截取STR串中从头开始到END的子串。

 

[root@jfht ~]# STR=123456789
[root@jfht ~]# echo "$STR" | cut -c3-4
34
[root@jfht ~]# START=3
[root@jfht ~]# END=4
[root@jfht ~]# echo "$STR" | cut -c$START-$END
34

[root@jfht ~]# echo "$STR" | cut -c$START-
3456789

[root@jfht ~]# echo "$STR" | cut -c-$END
1234

 

用awk substr截取子串

用awk命令来进行字符串截取,网上很多例子有错。

echo "$STR" | awk '{print substr($0,'$POS','$LEN')}'

echo | awk '{print substr("'"$STR"'",'$POS','$LEN')}'

截取STR的POS开始长度LEN的子串,POS从1开始算。

 

[root@jfht ~]# STR=123456789

[root@jfht ~]# echo "$STR" | awk '{print substr($0,3,4)}'
3456
[root@jfht ~]# POS=3
[root@jfht ~]# LEN=4
[root@jfht ~]# echo "$STR" | awk '{print substr($0,'$POS','$LEN')}'
3456

[root@jfht ctmw]# STR="123  456  789"

[root@jfht ctmw]# POS=3
[root@jfht ctmw]# LEN=4
[root@jfht ctmw]# echo "$STR" | awk '{print substr($0,'$POS','$LEN')}' 
3  4
[root@jfht ctmw]# echo | awk '{print substr("'"$STR"'",'$POS','$LEN')}'
3  4
[root@jfht ctmw]#

 

 

使用dd命令截取子串

用dd命令来进行字符串截取。

echo "$STR" | dd bs=1 skip=$POS count=$LEN 2>/dev/null

截取STR的POS开始长度LEN的子串,POS从0开始算。

info dd 写道
`bs=BYTES'
    Both read and write BYTES bytes at a time.
`skip=BLOCKS'
    Skip BLOCKS `ibs'-byte blocks in the input file before copying.
`count=BLOCKS'
    Copy BLOCKS `ibs'-byte blocks from the input file, instead of
everything until the end of the file.
 

[root@jfht ~]# STR=123456789
[root@jfht ~]# echo "$STR" | dd bs=1 skip=3 count=4
45674+0 records in
4+0 records out
4 bytes (4 B) copied, 6.553e-05 seconds, 61.0 kB/s
[root@jfht ~]# echo "$STR" | dd bs=1 skip=3 count=4 2>/dev/null
4567[root@jfht ~]# POS=3
[root@jfht ~]# LEN=4
[root@jfht ~]# echo "$STR" | dd bs=1 skip=$POS count=$LEN 2>/dev/null
4567[root@jfht ~]#

 

 

本文链接:http://codingstandards.iteye.com/blog/1164911   (转载请注明出处)

返回目录:Java程序员的Bash实用指南系列之字符串处理(目录) 

上节内容:Bash字符串处理(与Java对照) - 25.字符串分割(成数组)

下节内容:Bash字符串处理(与Java对照) - 27.转换大小写

 

Problem D: 将字符串插入到另一个字符串的指定位置(串) Problem D: 将字符串插入到另一个字符串的指定位置(串)Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 677  Solved: 409[Submit][Status][Web Board]Description将字符串t插入到字符串s中,在位置pos后插入。不得使用字符串操作函数,输出组合成的字符串。Input输入两个字符串(t和s)和要... 阅读详情

相关推荐

AJ-Report开源数据大屏存在远程命令执行漏洞

该平台可以通过post方式在validationRules参数对应值中进行命令执行,可以获得服务器权限,登陆管理后台接管大屏。如果被攻击者利用,危害后果十分严重。

swordheart的博客 387

bash的字符串操作(学习整理)

 字符串示例:      string=abcas2221111c  (1)字符串长度           echo ${#string}  # 13           echo `expr length $string` #13           echo `expr "$string" : '.*'` #13   (2) 字串起始位置匹配子字串的长度         命令: ...

林星语 380

自己动手写CPU(1)五级流水线及CPU第一条指令ori

自己动手写CPU(1)五级流水线及CPU第一条指令ori 动机 不知为何研一的自由时间突然多起来,可能人一闲下来就容易焦虑吧,hhhhhh。正好之前看到一本《自己动手写CPU》,就按照此书从头实做一遍MIPS指令集的CPU,也当做对大学课程的总结。之前看龙芯杯比赛的代码震惊到我了,想想那堆大佬本科在搞这东西而我本科在瓜瓜地刷分,感叹人之间的差距真的好大。痛定思痛,还是先动手做起来这才能假意安慰自己,我好像也不错。闲言少叙,让我们开始吧! 由于作者提供了各章实现的具体代码,所以该系列博客主要记录我过程中有哪些

谦豫 7077

js基础知识(一)slice substr substring

JavaScript slice() 方法 JavaScript String 对象 定义和用法 slice() 方法可提取字符串的某个部分,并以新的字符串返回被提取的部分。 语法 stringObject.slice(start,end) 参数 描述 start 要抽取的片断的起始下标。如果是负数,则该参数规定的是从字符串的尾部开始算起的位置。也就是说,-1 指字符...

lyp_story的博客 226

OK3588-C开发板Forlinx Desktop系统烧录与多媒体功能实战

本文详细介绍了OK3588-C开发板Forlinx Desktop系统的烧录步骤与多媒体功能实战。从硬件准备到软件工具配置,逐步解析RKDevTool烧录技巧,并深入测试摄像头、视频编解码及音频功能,帮助开发者快速掌握RK3588芯片的强大性能与Ubuntu系统的优化应用。

weixin_29190169的博客 417

Windows10下MATLAB2017a安装与破解实战:手把手教你搞定双镜像加载

本文详细介绍了在Windows 10系统下安装和破解MATLAB 2017a的完整步骤,包括双镜像加载、许可证配置及常见问题解决方案。通过手把手教程,帮助用户顺利完成安装并优化性能,特别适合工程计算领域的初学者和专业人士。

weixin_29053383的博客 418

讲解substr函数

`substr` 是编程中用于截取字符串的一个方法或函数,其功能是从一个字符串中提取出一部分子字符串。不同的编程语言中,这个功能的实现方式也会有不同。

Weiki的博客 879

最新2026年《网络数据安全风险评估办法》条款解读

大型企业集团IT变革下的零信任安全体系建设方案(55页).pptx。以数据安全为核心的安全立体防御体系解决方案(41页).pptx。让数据安全合规地创造价值(15页 PPT).pptx。大型集团数据安全应急预案(57页).docx。数据安全治理与评估服务业务介绍.pptx。数据安全管理实践(17页).pptx。大数据安全架构设计方案.pptx。大数据安全规划总体方案.pptx。数据库安全综合治理方案.pptx。医疗数据安全建设方案.pptx。数据安全框架规划图.pptx。数据安全治理方案.pptx。

cdfunlove的博客 46

java string 获取子串_从Java中的String获取子串

我有以下文字:...,Niedersachsen,NOT IN CHARGE SINCE: 03.2009, CATEGORY:...,现在我想提取NOT IN CHARGE SINCE:之后的日期,直到逗号。所以我只需要03.2009结果在我的子字符串。那我该如何处理呢?String substr = "not in charge since:";String before = s.substr...

weixin_28752743的博客 2793

PCB_Project.PrjPcb 4 Not in version control

Altium Designer中PCB项目出现"NOT in version control"错误的解决方法:1. 禁用不需要的版本控制集成(DXP→Preferences→Version Control);2. 清理项目缓存(Projects面板右键→Clean Project);3. 检查文件读写权限;4. 如无效可新建项目重新添加文件。如需使用SVN版本控制,需正确配置SVN客户端路径,创建或连接SVN仓库,并将项目文件提交至版本控制系统。注意新建SVN仓库必须使用空目录,建议使用

whm128的博客 1593

人形机器人电路板和算法分析

人形机器人电路板与算法深度剖析 电路板领域:人形机器人电子系统分为计算、驱动、感知、能源、通信五大模块。主控板采用高性能SoM(如NVIDIA Jetson AGX Orin),需满足严格电源完整性(PDN)与信号完整性(SI)要求;关节驱动板集成MCU、GaN/SiC功率器件及高精度编码器接口,采用刚柔结合PCB以适应狭小空间。挑战包括热-振可靠性(85°C/10G振动)、高密度互连(3mil线宽)及EMC兼容性。 算法领域:运动控制依赖MPC(模型预测控制)与强化学习(RL),实现实时动态平衡;感知算法

几十年资深高级架构师,技术专家的技术笔记。专注C、Java、Python、微服务、云原生、AI工程化及高并发系统分布式架构实战,分享源码剖析、性能调优与架构治理经验。 305

Java程序员的Bash实用指南系列之字符串处理(目录)

Java程序员的Bash实用指南系列之字符串处理(目录) 文章   在一般的计算机编程语言中,字符串处理是很重要的一块,Bash也是如此,如果掌握了字符串的处理,基本上就能够应付大部分的编程工作了。在Unix/Linux操作系统中,很多时候需要使用多个命令一起配合才能完成一个较复杂的任务,Shell提供了管道线、重定向、结构化编程等方式,把这些命令粘合在一起。因此,命令之间的接口数据的处理

Nicholas的专栏 QQ1295794532 1139

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

【Java入门到精通】*基础篇

Java入门教程摘要(1-6期) 本系列从零讲解Java,基于Java 8 LTS版本。 Java历史与特性:1995年Sun公司发布,以跨平台、面向对象为核心优势,应用于后端、安卓、大数据等领域。 跨平台原理:通过JVM将字节码转换为机器码,实现"一次编写,到处运行"。 环境组件:JDK(开发工具包)⊃ JRE(运行环境)⊃ JVM(虚拟机),开发需安装JDK。 安装配置:提供Windows/Mac的JDK安装指南,强调路径无中文/空格。 环境变量:设置JAVA_HOME指向JDK路径,Path添加bin

2301_81248642的博客 930

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Redis企业实战:从基础到高级架构的完整指南(不全)

《Redis企业级实战与高级架构》课程摘要 本课程全面讲解Redis从基础到企业级应用的完整知识体系,分为基础篇、实战篇和高级篇三部分,总时长超过13小时。 基础篇(12章): 系统讲解Redis核心概念、安装部署和5种数据结构 详细演示String/Hash/List/Set/ZSet等命令操作 深入讲解Key层级设计、通用命令和图形化工具 实战篇(30章): 通过黑马点评项目实现短信登录、商户缓存等10大业务场景 解决缓存穿透/击穿/雪崩问题,实现分布式锁方案 使用Lua脚本、Redisson和消息队列

2501_90864902的博客 267

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

java取子串_JAVA中取子字符串的几种方式

有这样一串字符串:String s = "共 100 页, 1 2 3 4...";假如我想把"100"给取出来,该如何做?方法一: 采用split的方式System.out.println(s.split(" ")[1]);或者System.out.println(s.split("\\s")[1]);假如空" "有多个时,可以这样:System.out.println(s.split("\\s...

weixin_39907596的博客 870

java取子串_Java中获取子字符串的几种方法示例

首先假如有这样一串字符串:String s = "共 100 页, 1 2 3 4...";假如我想把"100"给取出来,该如何做?方法一: 采用split的方式System.out.println(s.split(" ")[1]);或者System.out.println(s.split("\\s")[1]);假如空" "有多个时,可以这样:System.out.println(s.split(...

weixin_31162865的博客 2400

oracle的substr函数的用法

oracle的substr函数的用法  取得字符串中指定起始位置和长度的字符串   substr( string, start_position, [ length ] )  如:      substr('This is a test', 6, 2)     would return 'is'      substr('This is a test', 6)     would retu

lfctp2008的专栏 750

Python基础练习

title : Python基础练习 1、 执行Python 脚本的两种方式 在Windows中执行,通过cmd 进入相应的Python文件(如hello.py)的路径,在cmd中输入python hello.py就可以执行。 通过IDE软件,如pycharm,ctrl+shift+F10执行脚本 在Linux系统中: 在Python文件的开头需要添加python的路径,不清楚路径通...

dianyi3179的博客 845

把一个字符串用指定的字符作为分隔符分割成若干个子串输出

#include <stdio.h> #include <string.h>void substr(char a[],char separate) { char buf[strlen(a)]; int i=0; int j=0; int k=0; while(a[i]!='\0') { if((buf[j]=a[i])==separat

maozi1992的专栏 1471

04-26 基础练习题

一、 true 7.float(32) -32.0 13.bool(0) ? 2.False ,数据类型不一样 8.float(‘3.21’)-3.21 ...

weixin_46400833的博客 2902

字符串中的slice(),substr(),substring()三种提取字符串的方法总结

1、slice() slice()方法可提取字符串的某个部分,并以新的字符串返回被提取的部分。 语法:str.slice(start,end),截取str从start到end的所有字符(包含起始位置,不包含结束位置) 说明:start和end都可以是负数,如果是负数,就从字符串的尾部开始算起,例如-1就是最后一个字符,-2就是倒数第二个字符,一次类推 如果未指定end参数,则截取从 sta...

冰雪为融的博客 2万+

JAVA中String常见的七种用法(参考笔记)

以下是string的七种用法,注意哦,记得要时常去查看java的API文档,那个里面也有很详细的介绍 1。获取        1.1:字符串中包含的字符数,也就是字符串的长度。                 int length():获取长度        1.2:根据位置获取位置上某个字符。                 char charAt(int index)

LiuxBoy的专栏 1209

Java截取String字符串的几种方法

方法一,指定字符,截取字符串,返回字符串数组: String str = "abcd,123,123abc,fij23"; String[] strs=str.split(","); 方法二,指定索引号,截取字符串: 将字符串从索引号为5开始截取,一直到字符串末尾。(索引值从0开始): String str = "abcdefghijklmnopqrstuvwxyz"; str.substri...

qq_36216193的博客 6万+
上一篇: Bash字符串处理(与Java对照) - 25.字符串分割(成数组)
下一篇: 快速修改Linux的某网卡IP地址
codingstandards
博客等级 码龄16年 12粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值