我有这个代码
String speed_string = "baka baka saka laka";
String[] string_array = speed_string.split(" ");
System.out.println(string_array.length);
Run Code Online (Sandbox Code Playgroud)
当我运行它时它返回值1.这是为什么?好像只有字符串的第一个单词才会被保存.
我有一个GET请求类型字符串,我需要使用python解析.
blahdeblahdeblah?query=This is the query&time=8:30
Run Code Online (Sandbox Code Playgroud)
有没有人知道提取我想要的字符串的方法,这样我就可以做类似的事情
query= This is the query
time= 8:30
Run Code Online (Sandbox Code Playgroud)
请记住,我的一些字符串可能没有时间.所以举个例子
blahdeblahdeblah?query=This is a query without a time
Run Code Online (Sandbox Code Playgroud)
我也需要处理.我怎么能这样做?我不确定像splitstring这样的东西会对此有用,因为可以选择是否有一些变量.
x='2013:02:01'
y,m,d=x.split(':')
Run Code Online (Sandbox Code Playgroud)
生成y,m,d作为字符串.但是如何仅使用1行生成它们作为整数
失败:
y,m,d=int(y.split(':'))
y,m,d=int(y),int(m),int(d)=y.split(':')
Run Code Online (Sandbox Code Playgroud) 假设我们有输入:"喜欢"输出应该是:"li ke".
我试过这个方法:
String mystring = TextBox1.Text;
String[] mysplit = mystring.Split(new Char[]{' ',','});
Label3.Text = mysplit[0];
Label5.Text = mysplit[1];
Run Code Online (Sandbox Code Playgroud)
但是如果有多个单词并且它们之间有空格和冒号,则此方法将拆分.我想要的是一个单词被分成两个部分,并以一个或两个标签显示
我想让这个2命令更短,如果可能的话,1行.
my $id = shift;
my @splittedID = split(" ", $id);
return $splittedID[0];
Run Code Online (Sandbox Code Playgroud)
但它应该具有相同的功能.谢谢
String data = line.split(":")[1];
String location = data.split("|")[0];
String type = data.split("|")[1];
System.out.println("D: " + type);
int x = Integer.parseInt(location.split("-")[0]);
int y = Integer.parseInt(location.split("-")[1]);
int t = Integer.parseInt(type);
Run Code Online (Sandbox Code Playgroud)
输入此解析器的原始字符串格式为"DATA:3,3 | 1".我正在尝试将其解析为"DATA:x,y| t" 的格式.问题是location当字符串从字符串中分离时,该字符串是空白的data.为什么?
我有一个文本文件admin.dat,如下所示:
blackranger|sdasdasdasd23123|1000
blueranger|sdasdasdasdwhhh22|1000
brownranger|lppsadospd123|1000
Run Code Online (Sandbox Code Playgroud)
我试图读取每一行,使用|作为我的分隔符并输出到每个部分的控制台.
代码:
package testing;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class Testing {
public static void main(String[] args) {
Scanner filereader = null;
try {
filereader = new Scanner(new File("./src/testing/players.dat"));
String data;
while(filereader.hasNextLine()) {
String foo = "abc|123|a213";
String[] bar = foo.split("|");
for (int i = 0; i < 3; i++) {
System.out.println(bar[i]);
}
}
} catch (FileNotFoundException e) {
System.out.println("File not found");
} catch (IOException e) { …Run Code Online (Sandbox Code Playgroud) string[] array = indexAndProperty.Split(new char['.']); // [0].PreCondition
Run Code Online (Sandbox Code Playgroud)
为什么数组只有一个带字符串的元素"[0].PreCondition"?
我预期由点到分割字符串,并获得2种元素"[0]"和"PreCondition".
String s = "Total Count :2, Correct Count :1, Wrong Count:1, Correct :India is great,, Wrong: where aer you";
Run Code Online (Sandbox Code Playgroud)
我想要的是:
在int变量中.
这对我来说还是个新鲜事,我希望你们能帮助我.
我有一个文件,我必须通过块(基于时间戳)读取块.所以我使用awk在两个时间间隔之间读取,然后我必须进一步处理数据.为此,我必须阅读我从awk Line By Line收到的字符串.当我使用新字符执行拆分时,它不会拆分,但只有所有字符串都保留在第一个字段中.我使用了不同的转义字符但没有任何成功.
我的主要目的是逐行读取字符串.
$cmd = "awk '\$0>=from&&\$0<=to' from=\"$currentTime\" to=\"$nextTime\" Output.txt";
$dataChunk = system ($cmd);
my @lines = split /[\r\s\v\V\n]+/, $dataChunk;
foreach my $line (@lines) {
chomp;
$timeStamp1 = (split /-/, $line)[1];
print "\n$timeStamp1\n";
exit;
}
Run Code Online (Sandbox Code Playgroud)