我正在使用VB .NET,我知道Union通常使用ByRef,但在VB中,字符串通常被处理为好像它们是原始数据类型.
因此,问题在于:
Sub Main() Dim firstFile,secondFile As String(),resultingFile As New StringBuilder firstFile = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\1.txt").Split(vbNewLine) secondFile = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\2.txt").Split(vbNewLine) For Each line As String In firstFile.Union(secondFile) resultingFile.AppendLine(line) Next My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\merged.txt",resultingFile.ToString,True) End Sub
1.txt包含:
一个
b
C
d
Ë
2.txt包含:
b
C
d
Ë
F
G
H
一世
Ĵ
运行代码后,我得到:
一个
b
C
d
Ë
b
F
G
H
一世
Ĵ
任何使联盟功能都像数学对应的建议?
Linq Union确实按照您的意愿执行.确保输入文件正确(例如,其中一行可能在换行符之前包含空格)或者在拆分后修剪字符串?
var list1 = new[] { "a","s","d" }; var list2 = new[] { "d","a","f","123" }; var union = list1.Union(list2); union.Dump(); // this is a LinqPad method
在linqpad中,结果是{“a”,“s”,“d”,“f”,“123”}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。