删除部分字符串(Remove part of string in Java)
我想从一个字符中删除一部分字符串,即:
原始字符串:曼彻斯特联合(与好玩家)
未来的结果:曼联
I want to remove a part of string from one character, that is:
Source string:
manchester united (with nice players)
Target string:
manchester united
原文:/questions/8694984
2019-11-07 13:19
满意答案
有多种方法可以做到这一点。 如果您有要替换的字符串,可以使用replace或replace String类的所有方法。 如果您想要替换一个子字符串,您可以使用substring API获取子substring 。
例如
String str = "manchester united (with nice players)";
(("(with nice players)", ""));
int index = ("(");
((0, index));
要替换“()”内的内容,您可以使用:
int startIndex = ("(");
int endIndex = (")");
String replacement = "I AM JUST A REPLACEMENT";
String toBeReplaced = (startIndex + 1, endIndex);
((toBeReplaced, replacement));
There are multiple ways to do it. If you have the string which you want to replace you can use the replace or replaceAll methods of the String class. If you are looking to replace a substring you can get the substring using the substring API.
For example
String str = "manchester united (with nice players)";
(("(with nice players)", ""));
int index = ("(");
((0, index));
To replace content within "()" you can use:
int startIndex = ("(");
int endIndex = (")");
String replacement = "I AM JUST A REPLACEMENT";
String toBeReplaced = (startIndex + 1, endIndex);
((toBeReplaced, replacement));
2014-12-11
相关问答
你只需要逃避这段时间: a
gsub("\\..*","",a)
[1] "NM_020506" "NM_020519" "NM_001030297" "NM_010281" "NM_011419" "NM_053155"
You just need to escape the pe...
有多种方法可以做到这一点。 如果您有要替换的字符串,可以使用replace或replace String类的所有方法。 如果您想要替换一个子字符串,您可以使用substring API获取子substring 。 例如 String str = "manchester united (with nice players)";
(("(with nice players)", ""));
int index = ("("...
这里有很多问题: 您的StringBuilder未使用输入String初始化。 它应该是StringBuilder sb = new StringBuilder(str); 因此,它总是空的。 substring和delete方法适用于最后一个索引,不包括在内。 因此,从索引1开始获取长度为3的子字符串,需要调用(1, 4) 。 更正代码: public static String delDel(String str) {
StringBuilder sb = n...
使用()方法从字符串的开始和结尾处除去空格(空格,新行等)。 String trimmedString = ();
Use () method to get rid of whitespaces (spaces, new lines etc.) from the beginning and end of the string. String trimmedString = ();
只有两个简单的可能性 String str = "12/16/2011 12:00:00 AM";
// method 1: with
(0, (' '));
// method 2: , with limit 1 to ignore everything else
(" ", 1)[0];
Just two simple possibil...
做: sed 's/_task-[^_]*//'
[^_]*将匹配下一个_ 。 例: $ sed 's/_task-[^_]*//' <<
sub-285345_dir-28_epi.nii
$ sed 's/_task-[^_]*//' <<
sub-285345_dir-11_epi.
Do: sed 's/_ta...
你可以简单地这样做: int number = (int) totalAmountPlusTaxes;
要么 string totalAmountPlusTaxes = ("{0:C0}",totalamountWithTaxes);
You can simply do it like this: int number = (int) totalAmountPlusTaxes;
or string totalAmountPlusTaxes = ...
您将需要使用fileparts的第一个输出 ,因为它可以保证在所有平台上都能正常工作。 fileparts函数是一个内置的设计,用于将路径分为目录,文件名和文件扩展名。 string = '/disk1/home/alb/main/directory1/'
part = fileparts(string);
如果你真的需要斜线(如果你使用fullfile来(正确)构建一个新路径,你不应该这么做),那么你可以使用filesep将它添加到最后。 part_with_slas...
matches()尝试再次匹配整个字符串模式。 如果你想在字符串中找到你的模式,使用find() , find()将搜索字符串中的下一个匹配项。 你的代码可能完全相同: if(())
return (0, ());
matches() tries to match the whole string again the pattern. If you want to find your pattern within a string, us...
使用正则表达式: var str2 = (/-.{8}\.ext$/, '.ext');
如果扩展名可能会更改(例如.odt而不是.txt ,请使用 var str2 = (/-.{8}(\.[\d\w]+)$/, '$1');
With a regular expression : var str2 = (/-.{8}\.ext$/, '.ext');
If the extension may change (for ...
相关文章
命令格式: SET key value 把字符串值value存储到key中。如果存在此key,SE
...
Java String类 字符串广泛应用在Java编程中,在Java中字符串属于对象,Java提
...
无论是对程序的本地化还是国际化,都会涉及到字符编码的转换的问题。尤其在web应用中常常需要处理中文字符
...
Python 字符串操作,字符串序列用于表示和存储文本,python中字符串是不可变的,一旦声明,不能
...
Java 获取字符串中第N次出现的字符位置的背景:截取字符串的时候,大家应该都是
...
相信大家对 String 和 StringBuffer 的区别也已经很了解了,但是估计还是会有很多同志
...
今天遇见一个问题.不知道怎么解决. 如: 自己建立了一个文件 里面存放这样的 键值
...
转载请注明出处:/lonelytrooper/article/
...
有字符串"00000000"如何写一段代码将该字符串的任一位修改为1那 问题补充
...
Splitter trimResults(CharMatcher trimmer)返回分离器的行为等同
...
最新问答
如果启用了复制处理程序,请确保将其置于其中一个安全角色之后。 我见过人们做的另一件事是在不同的端口上运行admin。 最好在需要auth的页面上使用SSL,这样你就不会发送明确的密码,因此管理和复制将发生在8443上,而常规查询将在8080上发生。 如果您要签署自己的证书,请查看此有用的SO页面: 如何在特定连接上使用不同的证书? I didn't know that /admin was the context for SOLR admin because /admin does not re
第一:在您的样本中,您有: 但是你在询问 //td[@class=‘CarMiniProfile-TableHeader’] (注意TableHeader中的大写'T')。 xpath区分大小写。 第二:通过查询// td [@ class ='CarMiniProfile-TableHeader'] / td,你暗示你在外部td中有一个'td'元素,而它们是兄弟姐妹。 有很多方法可以在这里获得制作和模型
这是你的答案: /gPsdk/40/ .preloader-container { position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; background: #FFFFFF; z-index: 5; opacity: 1; -webkit-transition: all 500ms ease-out;
问题是,在启用Outlook库引用的情况下, olMailItem是一个保留常量,我认为当您将Dim olMailItem as ,这不是问题,但是尝试设置变量会导致问题。 以下是完整的解释: 您已将olMailItem声明为对象变量。 在赋值语句的右侧,在将其值设置为对象的实例之前,您将引用此Object 。 这基本上是一个递归错误,因为你有对象试图自己分配自己。 还有另一个潜在的错误,如果之前已经分配了olMailItem ,这个语句会引发另一个错误(可能是
我建议使用wireshark /通过记录(“捕获”)设备可以看到的网络流量副本来“监听”网络上发生的对话。 当您开始捕获时,数据量似乎过大,但如果您能够发现任何看起来像您的SOAP消息的片段(应该很容易发现),那么您可以通过右键单击并选择来快速过滤到该对话'关注TCP Stream'。 然后,您可以在弹出窗口中查看您编写的SOAP服务与Silverlight客户端之间的整个对话。 如果一切正常,请关闭弹出窗口。 作为一个额外的好处,wireshar
Android默认情况下不提供TextView的合理结果。 您可以使用以下库并实现适当的aligntment。 /navabi/JustifiedTextView Android Does not provide Justified aligntment of TextView By default. You can use following library and achieve proper aligntment. /
你的代码适合我: class apples { public static void main(String args[]) { ("Hello World!"); } } 我将它下载到c:\ temp \ 。 以下是我编译和运行的方式: C:\temp>javac -cp . C:\temp>dir apples Volume in drive C is HP_PAV
12个十六进制数字(带前导0x)表示48位。 那是256 TB的虚拟地址空间。 在AMD64上阅读wiki(我假设你在上面,对吗?)架构/wiki/X86-64 12 hex digits (with leading 0x) mean 48 bits. That is 256 TB of virtual address space. Read wiki on AMD64 (I assume that you are on it, right?) ar
这将取决于你想要的。 对象有两种属性:类属性和实例属性。 类属性 类属性对于类的每个实例都是相同的对象。 class MyClass: class_attribute = [] 这里已经为类定义了MyClass.class_attribute ,您可以使用它。 如果您创建MyClass实例,则每个实例都可以访问相同的class_attribute 。 实例属性 instance属性仅在创建实例时可用,并且对于类的每个实例都是唯一的。 您只能在实例上使用它们。 在方法__init__中定