subString的用法小结

String中的substring()方法详解 substring()方法是 Java 中 String 类的一个常用方法,用于从一个字符串中提取其中的子串。 阅读详情
AI摘要

本文总结了substring方法的三种常用用法。第一种是从指定起始位置截取到字符串末尾;第二种是从起始位置截取到指定结束位置(不包含结束位置字符);第三种是结合indexOf方法动态截取到指定字符位置。示例代码展示了Java中如何使用substring实现字符串截取操作。


subString是Java提供的一种字符串截取方法,通常我们可以用参数来控制截取的字符串。

subString常用方法一:

String a = “123456anbdc”;
String b = a.substring(1);
此时得到的为字符串a从下标为1的位置开始截取到最后的值,也就是23456anbdc;

subString常用方法二:

String a = “123456anbdc”;
String b = a.substring(1,5);
此时得到的为字符串a从下标为1的位置开始截取到下标为5的位置的值(不包括下标为5的值),也就是2345;

subString常用方法三:

String a = “123456anbdc”;
String b = a.substring(1,a.indexOf(“b”));
此时得到的为字符串a从下标为1的位置开始截取到指定字符串“b”的值,也就是23456an;
(注:如指定字符串有多个,以第一个为主)
(说明:a.indexOf(“b”)就是取字符串“b”的下标,和上面的用法本质是一样的)

substring 和 substr 的区别 如果为负值,则被看作 a.length + start,其中 a.length 为字符串的长度(例如,如果 start 为 -3,则被看作 a.length + (-3))。substring() 的第二个参数表示索引结束的位置,提取的结果不包括该索引的值。substr() 的第二个参数表示要提取的字符数量,不选默认表示提取到结束的位置;length:可选,提取的字符数量,不选就是全部,也就是到结束的位置。start:必填,非负整数,需要截取的第一个字符的索引。该索引位置的字符作为返回的字符串的首字母。 阅读详情

相关推荐

别再手动写JSON了!用Node-RED OPC UA节点5分钟搞定楼宇温湿度数据采集

本文介绍了如何利用Node-RED和OPC UA节点快速实现楼宇温湿度数据的自动化采集与JSON格式转换。通过可视化工具Node-RED,开发者无需编写复杂代码,5分钟内即可完成从传感器到数据输出的全流程配置,大幅提升智慧楼宇和工业物联网项目的实施效率。

weixin_30368405的博客 432

subString的用法

订阅专栏 substring()的作用就是截取父字符串的某一部分 public String substring(int beginIndex, int endIndex) 第一个参数int为开始的索引,对应String数字中的开始位置, 第二个参数是截止的索引位置,对应String中的结束位置 1、取得的字符串长度为:endIndex - beginIndex; 2、从beginIndex开始取,到endIndex结束,从0开始数,其中不包括endIndex位置的字符 代码示例如下: package co

qq_45740126的博客 3万+

NE555构成多谐振荡器及三角波、正弦波的生成(附工程文件)

NE555构成多谐振荡器及三角波、正弦波的生成 续上一篇:NE555基本原理及相关公式的推导

qq_49979053的博客 5万+

substring()方法

substring():截取字符串中介于两个指定下标之间的字符。 用法: 两个参数: 字符串.substring(参数1,参数2); 参数1:字符串截取的起始下标,非负的整数 如果此参数是0,则是从字符串的第一个字符开始截取 参数2:截取结束位置的索引下标 注意:截取的结果,不包括结束位置的字符 示例: var str="abcdefghijklmn"; var res=str.substring(2,6); console.log(res); 结果re

小夏的博客 9万+

PWM(脉宽调制)技术详解:从基础到应用实践示例

PWM(脉宽调制)技术是嵌入式系统中一项重要的控制技术,通过调节脉冲宽度来实现对模拟设备的精准控制。从LED亮度到电机速度,PWM的应用场景非常广泛。对于嵌入式学习者来说,理解PWM的工作原理、掌握其配置方法,不仅能提升编程能力,还能为更多复杂系统的开发打下坚实的基础。

SpringWJN的博客 6327

轻量级替代方案:用AIFlowy + Ollama在本地快速搭建一个可用的AI智能体平台

本文介绍了如何使用AIFlowy和Ollama在本地快速搭建轻量级AI智能体平台,涵盖从环境准备到智能体集成的全流程。通过简化部署步骤和优化性能,15分钟内即可完成搭建,适用于原型验证和小团队协作,显著提升开发效率。

weixin_29207533的博客 219

substring()用法

(2)substring(0,5)这个只含开头不含结尾,因此截取是截取两个字符,从第一个到第二个字符,不包含第三个。(即只取1-5的字符,其余不取)(3)substring(5)这个表示截掉前两个,得到后边的新字符串。(即除了1-5的字符不取,其余都拿)(1)substring是用来截取字符串的,根据参数的个数不同,方法含义也不同;

weixin_42060331的博客 1万+

用VINS-Fusion跑通EuRoC数据集:Ubuntu22.04+ROS2环境下的保姆级评测指南

本文详细介绍了在Ubuntu22.04和ROS2 Humble环境下使用VINS-Fusion处理EuRoC数据集的完整流程。从环境配置、数据集转换到参数调优和性能评估,提供了一套全面的多传感器融合分析方案,帮助开发者在无人机精准定位场景中实现高效部署与优化。

weixin_29212867的博客 517

java中substring用法_JAVA中字符串函数subString的用法小结

本篇文章主要是对JAVA中字符串函数subString的用法进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助String str;str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str;str=str.substring(int beginIndex,int endIndex);截取str...

weixin_42508058的博客 1049

【以太网硬件十九】SGMII到底能不能直接出光模块?

详细解释为什么SGMII可以直接出光模块及其使用限制

highman110的博客 1万+

9.27华为OD机试真题 新系统 - 均衡调度 (Java/Py/C/C++/Js/Go)

9.26华为OD机试真题 新系统 - 均衡调度 (Java/Py/C/C++/Js/Go)

算法大师! 496

JAVA中字符串函数subString的用法小结

String str; str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str; str=str.substring(int beginIndex,int endIndex);截取str中从beginIndex开始至endIndex结束时的字符串,并将其赋值给str; demo:

ruiguang21的博客 3702

多智能体系统在军事仿真中的应用:AI人工智能战略推演

本文旨在全面解析多智能体系统在军事仿真领域的应用技术,重点探讨AI驱动的战略推演系统的设计原理和实现方法。研究范围涵盖从基础理论到实际应用的完整技术栈。本文采用从理论到实践的递进结构,首先介绍核心概念,然后深入算法实现,最后展示实际应用案例和未来展望。多智能体系统(MAS):由多个相互作用的智能体组成的分布式系统军事仿真(Military Simulation):通过计算机模拟军事行动和战争场景战略推演(Strategic Wargaming):通过模拟推演评估军事战略的有效性更高保真度的仿真。

AI天才研究院 1777

substring用法Java,JAVA中字符串函数subString的用法小结

String str;str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str;str=str.substring(int beginIndex,int endIndex);截取str中从beginIndex开始至endIndex结束时的字符串,并将其赋值给str;demo:class Test{publ...

weixin_30336529的博客 390

深度学习工具包 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")

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

java的substring函数_JAVA中字符串函数subString的用法小结

导读热词String str;str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str;str=str.substring(int beginIndex,int endIndex);截取str中从beginIndex开始至endIndex结束时的字符串,并将其赋值给str;demo:class Test{...

weixin_36257799的博客 638

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

java的substring_JAVA中字符串函数subString的用法小结

String str;str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str;str=str.substring(int beginIndex,int endIndex);截取str中从beginIndex开始至endIndex结束时的字符串,并将其赋值给str;demo:class Test{publ...

weixin_39978444的博客 175

VC中sqlite的使用

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

php substring indexof,js中substr,substring,indexOf,lastIndexOf的用法小结

js中substr,substring,indexOf,lastIndexOf等的用法1.substrsubstr(start,length)表示从start位置开始,截取length长度的字符串。var src="images/off_1.png";alert(src.substr(7,3));弹出值为:off2.substringsubstring(start,end)表示从start到end...

weixin_35973657的博客 322

js中substr,substring,indexOf,lastIndexOf的用法小结

js中substr,substring,indexOf,lastIndexOf等的用法 1.substr substr(start,length)表示从start位置开始,截取length长度的字符串。 var src=”images/off_1.png”; alert(src.substr(7,3)); 弹出值为:off 2.substring substring(start,e...

程序员一代码搬运工 131

java中字符串函数_JAVA中字符串函数subString的用法小结

string str;str=str.substring(int beginindex);截取掉str从首字母起长度为beginindex的字符串,将剩余字符串赋值给str;str=str.substring(int beginindex,int endindex);截取str中从beginindex开始至endindex结束时的字符串,并将其赋值给str;demo:class test{publ...

weixin_39960019的博客 149

java字符串函数_JAVA中字符串函数subString的用法小结

String str;str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str;str=str.substring(int beginIndex,int endIndex);截取str中从beginIndex开始至endIndex结束时的字符串,并将其赋值给str;demo:class Test{publ...

weixin_28728425的博客 185
上一篇: Oracle数据库备库,导库
下一篇: Oracle数据库建表语句
billxin0621
博客等级 码龄10年 58粉丝 37原创
评论 6
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值