Android TextUtils处理字符串

[Android]TextUtils.ellipsize()截取指定长度字符串(附图文混排) 参考:http://zilla.blog.51cto.com/3095640/984775 效果图: 实现代码: // 监听布局变化,直接获取显示的长度 txtDescription.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @O 阅读详情
对于字符串处理Android为我们提供了一个简单实用的TextUtils类,如果处理比较简单的内容不用去思考正则表达式不妨试试这个在android.text.TextUtils的类,主要的功能如下:

是否为空字符 boolean android.text.TextUtils.isEmpty(CharSequence str) 

拼接字符串 String android.text.TextUtils.join(CharSequence delimiter, Object[] tokens)

拆分字符串 String[] android.text.TextUtils.split(String text, String expression)

拆分字符串使用正则 String[] android.text.TextUtils.split(String text, Pattern pattern)

确定大小写是否有效在当前位置的文本 int android.text.TextUtils.getCapsMode(CharSequence cs, int off, int reqModes)

使用HTML编码这个字符串 String android.text.TextUtils.htmlEncode(String s)

另外,String[] android.text.TextUtils.split(String text, String expression)中的expression较特殊,如果采用

TextUtils.split(someString, "-");
来分割someString的话返回的将是错误结果,正确的用法应该是
TextUtils.split(line, ",|\\-");
转自:http://blog.youkuaiyun.com/fengye810130/article/details/9102263

 这几天看别人的代码,发现了这个类查了一下官方的api发现这个类还挺实用的。以前不知道走了弯路看来以后还得多看官方给的api了。对于字符串处理Android为我们提供了一个简单实用的TextUtils类,如果处理比较简单的内容不用去思考正则表达式不妨试试这个在android.text.TextUtils的类,

主要的功能如下:

1、

static boolean isEmpty( CharSequence str)
Returns true if the string is null or 0-length.
判断给定的字符串是否为空;很实用,例如从头EditText返回的是一个变量。如果这个变量本身为null值,那么你掉它的equals方法是要报错的。但是如果你调用TextUtils.isEmpty() 把这个变量作为参数传进去。只要这个参数为空或者为“”,都会返回真。所以,用官方给的更加严谨。而且。也十分方便。因为你单独去判断你还不是要写一个if语句判断。返回的还是一个boolean值,为何别人铺好的路不走呢?

2、

static  String substring( CharSequence source, int start, int end)    从起始位置start和结束位置end截取给定字符串source

3、

static boolean equals( CharSequence a,  CharSequence b)   比较a和b 包括a、b都为null的情况
android自动工具类TextUtils使用详解 今天,简单讲讲如何使用android自动的工具类TextUtils。 简单列举部分用法: Log.d(TAG, ---------------------------------); //字符串拼接 Log.d(TAG, TextUtils.concat(Hello, , world!).toString()); //判断是否为空字符串 Log.d(TAG, TextUtils.isEmpty(Hello) + ); //判断是否只有数字 Log.d(TAG, TextUtils.isDigitsOnly(Hello) + ); 立即下载

相关推荐

告别Keil手动分区!用CubeMX+VS Code一键生成带Bootloader的STM32 OTA工程

本文详细介绍了如何利用STM32CubeMX和VS Code实现STM32 OTA工程的自动化构建,告别传统Keil手动分区的繁琐流程。通过图形化配置Flash分区、自动生成链接脚本以及实现Bootloader跳转逻辑,开发者可以高效完成远程升级功能开发,显著提升嵌入式开发效率。

weixin_33720956的博客 389

TextUtils方法介绍

isEmpty 字符串是否为null或“” String a = "Android"; TextUtils.isEmpty(a)//false 空格返回的也是false isDigitsOnly 字符串是否全是数字 String c = "012345"; TextUtils.isDigitsOnly(c)//true isGraphic 字符串是否含有可打印的字符 S...

Errol's Blog 1561

【Linux】Petalinux使用QSPI FLASH引导启动

1. 预分配Flash空间使用Flash引导Petalinux做的系统,也有进阶的做法。部分图片和经验来源于网络,若有侵权麻烦联系我删除,主要是做笔记的时候忘记写来源了,做完笔记很久才写博客。1. 预分配Flash空间根据生成的bit文件大小估算BOOT.BIN文件的大小,为Flash大概分配四个分区:boot、bootenv、kernel、bootscr,分别存放BOOT.BIN文件、u-boot的环境变量、内核文件(image.ub/zImage/uImage等)、启动脚本boot.scr。

Tesseract_9527的博客 3375

关于Android的 TextUtil类

因为初学Android发现一些字符串的处理都用到TextUtil 于是

a641324093的专栏 996

ArcGIS标注(二分式、三分式、条件分类标注、上下标、牵引线、文字格式化…)

ArcGIS中的各种标注方法、可能遇到的问题和细节。

m0_73306837的博客 5268

玄机-Linux权限维持-后门

玄机-Linux权限维持-后门

m0_46439803的博客 764

Android中关于TextUtils工具的使用

当我们在进行一个字符串操作的时候,为了代码的严谨性,我们需要对我们即将操作的字符串进行非空判断,保证不要报空指针异常。这时候很多小伙伴想到了TextUtils.isEmpty的方法。但其实TextUtils不止有这一个方法。这里我列举出TextUtils中常用的四个方法,供大家需要时查阅。 isEmpty:判断字符串是否为空值。 getTrimmedLength:获取字符串去除头尾空格之后的长度。 isDigitsOnly:判断字符串是否全部由数字组成。 ellipsize:如果字符串超长,则返回按

水月洞天 1452

[VCS]门级仿真及SDF反标

摘要:门级仿真在STA工具普及后仍是验证的重要环节,主要用于检查SDC完备性、异步电路时序、网表完整性及为功耗分析提供波形。门级仿真分为不带时序反标的前仿和带SDF反标的后仿,后仿需加载SDF文件提供精确延时信息。VCS提供多种仿真选项控制时序检查行为,SDF反标可通过命令或系统函数实现。后仿需特别注意关闭notimingcheck选项以确保时序检查有效性,并建议检查SDF反标报告和波形验证延时一致性。

元直的博客 9790

TextUtils类-Android字符串处理类

这几天看别人的代码,发现了这个类查了一下官方的api发现这个类还挺实用的。以前不知道走了弯路看来以后还得多看官方给的api了。                        对于字符串处理Android为我们提供了一个简单实用的TextUtils类,如果处理比较简单的内容不用去思考正则表达式不妨试试这个在android.text.TextUtils的类, 主要的功能如下: 1、

linxuan0206的专栏 1864

【AI大模型应用开发】教你用AI轻松将你的知识库变为知识图谱(附完整代码,直接运行)

本文我们来介绍如何使用AI,将自己的知识库自动转换为知识图谱,并进行可视化展示。

同学小张的博客 3927

【图像去噪】论文复现:灵感源自MAE!进一步解决BSN的局限性,破坏真实噪声的空间相关性!AMSNet的Pytorch源码复现,跑通源码,原理详解!

论文题目:Asymmetric Mask Scheme for Self-Supervised Real Image Denoising —— 自监督真实图像去噪的非对称掩码方案【图像去噪】论文精读:Asymmetric Mask Scheme for Self-Supervised Real Image Denoising(AMSNet)AMSNet是基于PyTorch Lightning CLI深度学习框架编写的,比较适合复杂的大型任务,复用很方便,但是安装和环境配置问题太多。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 546

android--笔记--TextUtils字符串处理类

对于字符串处理Android为我们提供了一个简单实用的TextUtils类,如果处理比较简单的内容不用去思考正则表达式不妨试试这个在android.text.TextUtils的类,主要的功能如下:   是否为空字符 static boolean  isEmpty(CharSequence str)   拆分字符串  public static String[] split (

程序员的良师益友 646

ArcMap|时空地理加权回归(GTWR)

ArcGIS的GTWR插件下载地址:https://www.researchgate.net/publication/329518786_GTWR_ADDIN_Valid_till_Dec_31_2022 更详细的操作参考: https://www.bilibili.com/video/BV1fR4y1M7xB?spm_id_from=333.999.0.0 https://blog.csdn.net/weixin_40008135/article/details/112693520 双击“GTWR_Be

个人学习笔记 1万+

Android开发_字符串处理类-TextUtils类

对于字符串处理Android为我们提供了一个简单实用的TextUtils类,如果处理比较简单的内容不用去思考正则表达式不妨试试这个在android.text.TextUtils的类,主要的功能如下:   是否为空字符 static boolean  isEmpty(CharSequence str)   拆分字符串  public static String[]

移动智能 4173

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

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

Android字符串处理类-TextUtils类

对于字符串处理Android为我们提供了一个简单实用的TextUtils类,如果处理比较简单的内容不用去思考正则表达式不妨试试这个在android.text.TextUtils的类,主要的功能如下:   是否为空字符 static boolean  isEmpty(CharSequence str)   拆分字符串  public static String[] split (

@EddieYuan 997

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Android TextUtils类介绍——字符串的处理

对于字符串处理Android为我们提供了一个简单实用的TextUtils类,如果处理比较简单的内容不用去思考正则表达式不妨试试这个在android.text.TextUtils的类,主要的功能如下:是否为空字符 boolean android.text.TextUtils.isEmpty(CharSequence str) 拼接字符串 String android.text.TextUtils.jo

mimi5821741的专栏 616

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

字符串处理类(android.text.TextUtils)中的常用方法

String a = &amp;quot;Android&amp;quot;; String b = &amp;quot; Studio&amp;quot;; String c = &amp;quot;012345&amp;quot;; String d = &amp;quot; \n\t \b&amp;quot;; String e = &amp;quot;11-233-

热爱技术 1万+

TextUtils.isEmpty 作用

TextUtils.isEmpty 作用

qq_27494201的博客 809

安卓 Textutils 类的介绍

安卓中TextUtils类的用法

caicai1377的博客 563

TextUtils这是干什么的?

减少重复代码:避免手动实现isEmpty()equals()等基础逻辑。线程安全:所有方法均为静态工具方法,无状态依赖。兼容性处理:自动处理null值、空格等边界情况(如统计有效字符数)[citation:1][citation:3][citation:11]。如需具体方法参数或源码分析,可参考Android官方文档或上述搜索结果中的代码示例[citation:1-14]。

小新的博客 578
上一篇: Ecplise内存分析工具插件
下一篇: Android 异步
HabbyGe
博客等级 码龄16年 46粉丝 143原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值