我正在寻找一个脚本代码来搜索一个字符串的3个单词.
示例:
words = 'I am confused looking for 3 words from the front'
Run Code Online (Sandbox Code Playgroud)
预期成绩:
'I am confused'
Run Code Online (Sandbox Code Playgroud) use Data::Dumper qw(Dumper);
@arr=split('\/',"\Program Files\Microsoft VisualStudio\VC98\Bin\Rebase.exe");
print(Dumper \@arr);
Run Code Online (Sandbox Code Playgroud)
输出:
$VAR1 = [
'Program FilesMicrosoft VisualStudioVC98BinRebase.exe'
];
Run Code Online (Sandbox Code Playgroud)
所需输出:
$VAR1 = [
'Program Files',
'Microsoft VisualStudio',
'VC98',
'Bin',
'Rebase.exe'
];
Run Code Online (Sandbox Code Playgroud) 我的程序逐行读取数据文件,每行读取一个字符串.以下是一行示例:
13 0 150801 00010860 04 04 1 076 2270 999 2 0 1 0 16 04 07 054 0311 068 0135 064 0533 079 0139 075 0640 079 0135 088
我现在需要在有空格的地方拆分这个字符串.我编写了以下代码,但在运行时遇到错误.这是代码:
//用于存储WIM数据的矩阵String [] [] WIMdataMatrix = new String [WIMdataList.size()] [30];
//Splits the string lines in different elements and stores in matrix
for(int i = 0 ; i < WIMdataList.size() ; i++){
String[] temp = WIMdataList.get(i).split(" ");
for(int j = 0 ; j < 30 ; j++){
WIMdataMatrix[i][j] = temp[j]; …Run Code Online (Sandbox Code Playgroud) 我做了一个带有.cs文件的小项目,读取它们并返回文件中最常用的单词.但是,现在它返回最常见的单词是逗号.我怎么能这样分裂字符串忽略逗号?
例如:我有一个字符串:
,.?aa,b cdef cfed,abef abef abef,
现在它返回最常见的单词是'abef'并且它发生了2次(程序不计算第三个abef,最后是逗号的那个.)
另一个例子:
,.?aa,b cdef cfed,abef abef abef ,,,
这个现在返回最常见的单词是逗号','它发生了3次,但问题是 - 我希望我的程序忽略逗号并仅仅专注于单词.
namespace WindowsFormsApp8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private async void button1_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Text Documents |*.cs;*.txt", ValidateNames = true, Multiselect = false }) //openfiledialog (all .cs; all.txt)
{
if (ofd.ShowDialog() == DialogResult.OK) //if in file dialog a file gets selected
{
using (StreamReader …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的数组
const arr = [3,6,9,12,18,21,24,27,33,36];
Run Code Online (Sandbox Code Playgroud)
我希望将数组arr分成12、21和33的块。即在索引3、5和8处。我想生成另一个像这样的数组块。
const chunks = [[3,6,9,12],[18,21],[24,27,33],[36]];
Run Code Online (Sandbox Code Playgroud)
我在这里看到的解决方案基本上将数组拆分为“ n”个块。基本上我想在几个(指定)索引处拆分数组。
我不介意underscore.js / lodash解决方案。谢谢
在进行扫描仪,我要裂开输入两次:
先去掉任何空格String.split("\\s+");
那么剩下的字符串分割成字符String.split("(?!^)");
去掉空格之后,我似乎无法弄清楚如何使持有的全新的String我的String的一部分数组.
有了这个,我尝试了String = String.split(),但是没有用.
谷歌也没有帮助.
我需要帮助创建一个分割字符串的循环.到目前为止,我有以下代码.
System.out.println("*FILE HAS BEEN LOCATED*");
System.out.println("*File contains: \n");
List<String> lines = new ArrayList<String>();
while (scan.hasNextLine())
{
lines.add(scan.nextLine());
}
String[] arr = lines.toArray(new String[0]);
String str_array = Arrays.toString(arr);
String[] arraysplit;
arraysplit = str_array.split(":");
for (int i=0; i<arraysplit.length; i++)
{
arraysplit[i] = arr[i].trim();
System.out.println(arr[i]);
}
Run Code Online (Sandbox Code Playgroud)
其中一个字符串的例子就是
Firstname : Lastname : age
Run Code Online (Sandbox Code Playgroud)
我希望它将字符串拆分为另一个看起来像这样的数组:
Firstname
Lastname
age
Run Code Online (Sandbox Code Playgroud)
我在运行代码时仍然遇到错误,似乎当我将数组转换为字符串时,它会在字符串中放入逗号,因此当我尝试拆分字符串时它会导致问题:不,
我有一个带有示例文本的文本文件,如下所示:
"venezuela probes ex-oil czar ramirez over alleged graft scheme
caracas/houston (reuters) - venezuela is investigating rafael ramirez, a
once powerful oil minister and former head of state oil company pdvsa, in
connection with an alleged $4.8 billion vienna-based corruption scheme, the
state prosecutor's office announced on friday.
5.5 hours ago
— reuters
amazon ordered not to pull in customers who can't spell `birkenstock'
a german court has ordered amazon not to lure internet shoppers to its
online marketplace when …Run Code Online (Sandbox Code Playgroud) split ×10
string ×5
java ×3
arrays ×2
javascript ×2
.net ×1
c# ×1
list ×1
perl ×1
python ×1
python-2.7 ×1
python-2.x ×1
r ×1
regex ×1
sql ×1
sql-server ×1
t-sql ×1