我有一些字符串,如:
string [] foo = ["zxc", "asd", "qwe"];
Run Code Online (Sandbox Code Playgroud)
我需要string从他们那里创造.喜欢:(
"zxc", "asd", "qwe"是的,每个元素都需要引用并用另一个逗号分隔,但它应该是字符串,而不是字符串数组.
我怎么能在功能风格上做到这一点?
我有非常简单的代码应该从存档中提取数据:
import std.stdio;
import std.string;
import std.file;
import std.algorithm;
import std.zip;
void main()
{
string ar = `D:\ftp\s2-imfset_2015\IFPET-150101.zip`;
auto zip = new ZipArchive(ar.read);
foreach(ArchiveMember am; zip.directory)
{
writeln(am.expandedData);
}
}
Run Code Online (Sandbox Code Playgroud)
(感谢解释 abouteach和 map difference)。但是当我运行它时,它会[]在控制台上打印。
"只能抛出从Throwable类继承的类型".任何人都可以解释我.为什么不是每种类型都可扔掉?如果在doc中没有提及函数可以抛出异常,那么它是否意味着它没有异常?
例如,我认为下一个try-catch块可以工作.但事实并非如此.
try
{
writeln("(((((((((");
latestdtonpage = dts.sort!((a,b) => a>b).front; //latest date-time. from page.
}
catch(Exception e)
{
writeln("Can't select the latest Date from parsed date");
writeln(e);
}
Run Code Online (Sandbox Code Playgroud)
但是,例外情况下的输出是下一个(没有例外文本):
(((((((((
core.exception.AssertError@C:\D\dmd2\windows\bin\..\..\src\phobos\std\array.d(73
9): Attempting to fetch the front of an empty array of DateTime
----------------
0x0051C4C9 in _d_assert_msg
0x00468E78 in pure nothrow ref @property @nogc @safe std.datetime.DateTime std.r
ange.__T11SortedRangeTAS3std8datetime8DateTimeS473app19StackOverflowParser5parse
MFAyaZ9__lambda2Z.SortedRange.front() at C:\D\dmd2\windows\bin\..\..\src\phobos\
std\range.d(8418)
0x0044F908 in void app.StackOverflowParser.parse(immutable(char)[]) at D:\code\T
rendoMetr\source\app.d(173)
0x0044F700 in app.StackOverflowParser app.StackOverflowParser.__ctor(app.DBConne
ct) at D:\code\TrendoMetr\source\app.d(150)
0x0044F199 in …Run Code Online (Sandbox Code Playgroud) 这里是我想得到的关联数组的例子:
string [string] rlist = ["dima":"first", "masha":"second", "roma":"third"];
我读过的文本文件结构非常简单:
peter = fourth
ivan = fifth
david = sixth
string [string] strarr;
string txt = readText("test.txt");
foreach (t;txt.splitLines())
{
// ??
}
Run Code Online (Sandbox Code Playgroud)
有人可以建议吗?