我有一个字符串 "foo|bar|time||||etc|"
我想循环遍历每个条目并将它们一个一个地保存在ArrayList中.分隔符是"|".
例如,ArrayList应包含:
"foo"
"bar"
"date"
""
""
""
"etc"
""
Run Code Online (Sandbox Code Playgroud)
如何在ArrayList中保存每个字符串?
我用来Readline()从串口读取字符串.
但问题是字符串总是附加"\r"在最后.
我试过了
text.Replace("\r","");
Run Code Online (Sandbox Code Playgroud)
但它没有用.
还有其他选择吗?
我试图将字符串"02/13/2013"解析为日期时间,但它不起作用.(它没有将dt设置为dtResult的值,因为tryprase没有通过.
这是我在做的事情:
DateTime dtResult;
var dt = DateTime.MinValue;
if (DateTime.TryParseExact(dateString, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out dtResult))
{
dt = dtResult;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用c#制作MP3播放器,但我正在遭受这个错误
"无法将类型'string'隐式转换为'string []".
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
string[] f, p;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
f = openFileDialog1.SafeFileName;
p = openFileDialog1.FileName;
for (int i = 0; i < f.Length; i++)
{
listBox1.Items.Add(f[i]);
}
foreach(string d in open.FileNames)
{
listBox1.Items.Add(d);
}
}
}
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{ …Run Code Online (Sandbox Code Playgroud) 以下代码应输出2016年11月18日.第一个消息框输出2016年11月18日第二个消息框错误地输出2016年1月18日
第一个if语句中的代码是否正确,或者我是否应该应用不同的格式.我正好在测试时注意到这个问题.
DateTime Output;
string Input = "2016/11/18";
if (DateTime.TryParseExact(Input, "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out Output))
{
MessageBox.Show(Output.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture));
}
if (DateTime.TryParseExact(Input, "yyyy/mm/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out Output))
{
MessageBox.Show(Output.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture));
}
Run Code Online (Sandbox Code Playgroud) 我需要验证我的字符串数组是空还是空.以下是我的代码.两者都不起作用.虽然数组未使用任何值进行初始化,但它显示为包含值.有人可以帮忙吗?
string abc[] = new string[3];
first code
if(abc != null)
{
}
second code
if(IsNullOrEmpty(abc))
{
}
public static bool IsNullOrEmpty<T>(T[] array)
{
return array == null || array.Length == 0;
}
Run Code Online (Sandbox Code Playgroud)