我将串联的字符串放入组件的Tag属性中:
Tag = String.Format("{0};{1};{2}", AThis, AThat, ATheOtherThing);
Run Code Online (Sandbox Code Playgroud)
现在我如何解决它,因为Tag是一个对象?试着这样做:
String[] someStuff = Tag.Split(';');
Run Code Online (Sandbox Code Playgroud)
我得到," '对象'不包含'Split'的定义,并且没有扩展方法'Split'接受'object'类型的第一个参数可以找到
我很难搞清楚如何拆分字符串,如下所示:
String str = "hi=bye,hello,goodbye,pickle,noodle
Run Code Online (Sandbox Code Playgroud)
这个字符串是从文本文件中读取的,我需要将字符串拆分为逗号之间的每个元素.所以无论文本文件读取什么,我都需要将每个元素拆分成自己的字符串.请记住,每个元素可以是任何长度,并且可以存在任何数量的'hi'等于的元素.有任何想法吗?谢谢!
我需要通过<br>重复2次或更多次的分隔符来分割字符串.我正在做:
'a<br><br><br><br>b'.split(/(<br>){2,}/)
Run Code Online (Sandbox Code Playgroud)
不幸的是,它按照String.split规范将组作为其中一个标记返回:
["a", "<br>", "b"]
Run Code Online (Sandbox Code Playgroud)
如何让它不返回组,只获取令牌:
["a", "b"]
Run Code Online (Sandbox Code Playgroud)
?
我正在搞乱一些字典,它应该将单词从一个文本框翻译成另一个文本框,反之亦然,但它并不像我喜欢的那样.该按钮的代码是:
private void button1_Click(object sender, EventArgs e)
{
string[] lines = File.ReadAllLines("C:/words.txt");
int i = 0;
var items = from line in lines
where i++ != 0
let words = line.Split('|')
where words.Count() > 1
select new
{
word = words[0],
translation = words[1]
};
foreach (var item in items)
{
if (textBox1.Text == item.word)
{
textBox2.Text = item.translation;
}
if (textBox2.Text == item.translation)
{
textBox1.Text = item.word;
}
else
{
label3.Text = ("not found");
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:不适用于"else if".
如果我有一串用逗号分隔的名称,我如何将它们全部分开并将它们作为单个元素放在一个新数组中?
例如 -
var str="How,are,you,doing,today?";
document.write(str.split(","));
Run Code Online (Sandbox Code Playgroud)
我想将每个元素直接放入数组中.这样做的方法是什么?
我有一个PHP数组如下:
Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 23
[4] => 7
[5] => 6
[6] => 14
[7] => 22
)
Run Code Online (Sandbox Code Playgroud)
我需要两个将这个数组拆分为两个数组的23值,如下所示:
Array
(
[0] => 16
[1] => 17
[2] => 18
)
Array(
[0] => 23
[1] => 7
[2] => 6
[3] => 14
[4] => 22
)
Run Code Online (Sandbox Code Playgroud)
任何人都可以通过PHP知道如何做到这一点.
在正则表达式方面,我真的是一个n00b.我一直试图在任何地方拆分字符串[----anything inside-----].
string s = "Hello Word my name_is [right now I'm hungry] Julian";
string[] words = Regex.Split( s, "------");
Run Code Online (Sandbox Code Playgroud)
结果将是 "Hello Word my name_is "和" Julian"
import java.lang.System;
public class Splitter{
public static void main(String args[]){
String path_separator = "Path separator is: " + System.getProperty("path.separator");
String str = "abc:def:gha";
System.out.println(path_separator);
String[] temp;
temp = str.split(path_separator);
for(int i=0; i<temp.length; i++)
System.out.println(temp[i]);
}
}
Run Code Online (Sandbox Code Playgroud)
java Splitter
路径分隔符是:
ABC:DEF:GHA
当我写作
temp = str.split(":");
Run Code Online (Sandbox Code Playgroud)
代替
java Splitter
路径分隔符是:
abc def gha
那么":"与":"有什么不同,或者我错过了什么?
同样的事情:
System.getProperty("line.separator")
Run Code Online (Sandbox Code Playgroud)
谢谢托马斯
当有一个新行(<br />)后跟一个数字时,我想分割我的字符串.
例如:
"aaaaaa<br />1 asdsad" // should be split
"bbbbbb<br />dfffgdft" // should not be split
"cccccc<br />2 asdasd" // should be split
Run Code Online (Sandbox Code Playgroud)
等等...
非常感谢您的帮助
我今晚努力工作以弄清楚如何将我的数组拆分成很多数组,由数组中的值定义
我可以拥有这个价值
$array = array (
array ("Apple", 10),
array("Ball", 5)
);
Run Code Online (Sandbox Code Playgroud)
然后我希望Apple拥有10个数组,其值为"Apple",而Ball需要5个数组,其值为"Ball"
然后我想出了这个,但输出似乎很奇怪..
$newarray = array();
foreach($array as $val):
for($i = 1; $i <= $val[1]; $i++):
$newarray[$i] = $val[0];
endfor;
endforeach;
print_r($newarray);
// Array ( [0] => Ball [1] => Ball [2] => Ball [3] => Ball [4] => Ball [5] => Ball [6] => Apple [7] => Apple [8] => Apple [9] => Apple [10] => Apple )
Run Code Online (Sandbox Code Playgroud)
希望你们理解我的问题,并希望有人能够弄明白.
提前谢谢.