Tag: 字符串

如何更换|| (两个管道)来自带有|的字符串 (一)管道

我在这个标签中得到了json格式的一些图像的响应: “xmlImageIds”:“57948916 || 57948917 || 57948918 || 57948919 || 57948920 || 57948921 || 57948 922 || 57948923 || 57948924 || 57948925 || 57948926 || 5794892” 我想要做的是使用字符串类的.split(“||”)分隔每个图像id。 然后使用此图像ID附加url并显示它。 我试过.replace(“\”|\”|”,”\”|”);但它不适合我。请帮助。 编辑:Shabbir,我试图根据您的评论更新您的问题。 如果我没弄错,请再次编辑它。

使用matcher()匹配字符串中的小数

我对匹配器有疑问。 目前我正在尝试读取一个字符串并将所有数字存储到一个数组中。 我的问题是,你如何尝试匹配整数和小数? 我有一系列双打叫: double [] thisArray = new double [20]; 在这个数组中,我试图存储我从字符串中提取的所有数字。 Matcher temp = Pattern.compile(“(\ d +)”)。matcher(x); 这是我对匹配器的function。 但这只匹配整数。 我想匹配整数和小数,如(5.2)。 但是我该怎么做? 我希望能够将整数和小数输入到我的字符串中。 任何帮助,将不胜感激。 谢谢!

将Java字符串传递给Javascript

我试图通过使用JSON格式的字符串初始化Javascript变量来加载包含数据的表。 如果我宣布: var data = new String(“{totalCount: ‘1’, identifier: ‘EntityID’, items: [{‘EntityID’:’1′,’Country’:’United States’,’Region’:”,’State’:’California’,’County’:’Santa Clara’,’City’:’San Jose’,’ZipCode’:’95134′}]}”); var d3 = eval(‘(‘ + data + ‘)’); 然后我的表将正确加载该行。 我尝试在脚本之前初始化Java字符串,然后将该对象传递给Javascript变量,如下所示: var data = new String(); // var data = new String(d) // tried this as well var d3 = eval(‘(‘ + data + ‘)’); 我的表无法识别这个,当我尝试以这种方式传递时,无法加载该行。 如何正确地将Java字符串传递给Javascript,以便我的表能够加载数据?

转换Char数组toString()返回质量

我试图反转一个字符串 1st convert to a Char[] 2nd reverse the Char[] 3rd convert CHar[] back to String by toString() method 我检查过toString()的输入是“abcd \ 0”,但输出是“[C @ 2e686cea”… 我有两个问题: 1. why toString() output this 2. what’s the best way to process String? convert to char[] or using StringBuffer? 这是我的代码: public class TestBench_1_2 { public static String reverseCStr (String str) […]

Java中的StringIndexOutOfBounds

我在这里有两个完全代码的副本,除了一个在for循环中有'<'而另一个有'<='。 有人可以解释为什么当我使用'<='时我得到索引超出范围的异常,但是它可以正常使用'<' 错误代码: for(int i = 0; i <= str.length(); i++) { int count = 0; char currentChar = str.charAt(i); for(int j = 0; j <= str.length(); j++) { if (currentChar == str.charAt(j) ) { count++; 工作代码: for(int i = 0; i < str.length(); i++) { int count = 0; char currentChar = str.charAt(i); for(int […]

如何知道字符串变量是否只包含java中的空格?

我有一个变量,它是一个字符串,如果变量只包含一个空格或多个空格,我想用“null”替换字符串。 我该怎么做?

当索引1中没有元素时,为什么不跟随java代码抛出java.lang.StringIndexOutOfBoundsException?

String str=”x”; System.out.println(str.substring(1)); 来自Javadoc: String java.lang.String.substring(int beginIndex) :返回一个新字符串,它是该字符串的子字符串。 子字符串以指定索引处的字符开头,并延伸到此字符串的末尾。

使用递归比较字符串以确定哪个字母顺序排在第一位Java

我正在尝试编写一个方法,使用递归来比较字符串str1和str2,并确定它们中的哪一个按字母顺序排列(即,根据字典中单词的使用顺序)。 如果str1按字母顺序排在第一位,则该方法应返回int 1 。 如果str2按字母顺序排在第一位,则该方法应该返回int 2 。 如果两个字符串相同,则该方法应返回int 0 。 我知道Java API中有一个compareTo方法,但我想知道如何在没有这个的情况下执行此操作 这是我到目前为止,但我不完全确定如何继续 } if (str1.length().equals(str2.length())) return 0; } else { (str.substring(1, str.length())); 任何想法将不胜感激

Java子串在while循环中的局部变量

我一直在尝试构建一个while循环来循环一个字符串,当它包含我正在寻找的’模式’时。 字符串是一个局部变量,在while循环上方声明,我无法在while循环中对其进行子串,因此每个连续循环都将查看字符串的下一部分。 如果我能解决这个问题,我将不胜感激 这是代码; 只是你有这个想法,在线列表通常作为数组列表输出,例如[阿德里安,鲍勃,巴迪] String onlineList = networkInput.nextLine(); //Declare a local variable for modified online list, that will replace all the strings that contain “, ” “[” and “]” String modifiedOnlineList = onlineList.replaceAll(“\\, “, “\n”).replaceAll(“\\[“, “”).replaceAll(“\\]”, “”); //Loop the modifiedOnlineList string until it contains “\n” while (modifiedOnlineList.contains(“\n”)) { //A local temporary variable for the […]

Java String.replace无效

这是我的代码。 String x = “1+√10”; x = x.replace(“.*”, “x”); System.out.println(x); 这应该返回”x”但是它返回”1+√10″ 。 为什么这不起作用?