有什么PHP方法可以做:
var filename = $_POST["filename"];
filename = filename.split(".").pop();
Run Code Online (Sandbox Code Playgroud)
我怎样才能在 PHP 中做同样的事情?
我有Java分割功能的问题我怎么能"\"像这样分割字符串,例如文本hello\world?我的代码是这样的:
str1 = "hello\\world";
String[] parts=str1.split("\\");
Run Code Online (Sandbox Code Playgroud) 我有这个字符串10-12-1999,我想将值存储到不同的变量,如下所示:
所以我有这个字符串data= 10-12-1999,我想像这样存储它
int day =10;
int month = 12;
int year = 1999;
Run Code Online (Sandbox Code Playgroud)
有人能指出我正确的方向吗?
拆分字符串时,如何确保分隔符位于两个字符之间,则不会被考虑?
// Input
String string = "a,b,[c,d],e";
String[] split = string.split(",");
// Output
split[0] // "a"
split[1] // "b"
split[2] // "[c"
split[3] // "d]"
split[4] // "e"
// Required
split[0] // "a"
split[1] // "b"
split[2] // "[c,d]"
split[3] // "e"
Run Code Online (Sandbox Code Playgroud) 我有:
0001-2015
如何将此字符串拆分为0001和2015?
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
int posn=0;
String reader;
String CSV = ",";
//String data []= new String [6]; //creates an array
File books = new File("books.txt");
if (books.exists() && books.length() != 0);
{
System.out.println("the file is there");
try {
BufferedReader in = new BufferedReader(new FileReader(books));
reader = in.readLine();
while (reader != null);
{
data = reader.split(CSV); //doesn't get past here
System.out.println("test");
Names[posn].setALL(data[0], Integer.parseInt(data[2]), data[1], data[3], data[4], Integer.parseInt(data[5]));
jSlider2.setMinimum(0);
jSlider2.setMaximum(posn);
posn++;
reader = in.readLine();
}
} catch (java.io.IOException e) { …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种干净的方法来分割Scala中的字符串中的换行符,无论换行符是CR和/或LF.我一直在使用.split一个基本的正则表达式,但它看起来很难看,因为标准库自然会为系统无关的代码封装 - 有没有标准的库函数呢?
提前致谢!
编辑:
我喜欢我的代码与系统无关,因为它是JVM的一大卖点.让我的代码知道硬编码字符串中的不同操作系统约定 - 文字正则表达式似乎(非常轻微地)打破了这一点.似乎应该由功能丰富的Scala标准库自然地抽象出来,我只是想知道是否存在内置方法.
嗨,我在将string.split值保存到数组时遇到麻烦,在使用以下代码后,数组为空。
Scanner in = new Scanner(System.in);
String input = in.nextLine();
in.close();
if(input.matches("^[0-6][.][0-6]$"))
{
b = false;
String[] coordinates = input.split(".");
int c1 = Integer.parseInt(coordinates[0]);
int c2 = Integer.parseInt(coordinates[1]);
playingfield.PlayTurn(c1, c2);
Run Code Online (Sandbox Code Playgroud)
它告诉我坐标[0]和[1]为空。
到那时为止的所有内容都可以正常运行,并且正则表达式是正确的,因为我可以在那里打印String,并且效果很好
我正在尝试将字符串转换为数组,但是我遇到了一些麻烦。字符串的缩短示例 -
"1 Afghanistan,2 Albania,3 Algeria,4 American Samoa,5 Andorra,6 Angola,7 Anguilla,8 Antarctica,9 Antigua and Barbuda,10 Argentina,11 Armenia,12 Aruba,208 Tanzania, United Republic of,209 Thailand"
Run Code Online (Sandbox Code Playgroud)
这里的问题是,我想用逗号分隔它,但是某些元素似乎也在使用逗号,就像208 Tanzania, United Republic of应该保持原样。
那么我可以在数字之间拆分它而不是通过 .split(',')
这是我的数据框架.
> data
Manufacturers
1 Audi,RS5
2 BMW,M3
3 Cadillac,CTS-V
4 Lexus,ISF
Run Code Online (Sandbox Code Playgroud)
所以我想分割制造商和模型,像这样,
> data
Manufacturers Models
1 Audi RS5
2 BMW M3
3 Cadillac CTS-V
4 Lexus ISF
Run Code Online (Sandbox Code Playgroud)
我很感激这个问题的任何帮助.非常感谢.