开发者

.Net Linq - Doing a operation on the subset

开发者 https://www.devze.com 2023-01-03 13:26 出处:网络
I need to ha开发者_如何学Gove the following : (name1 + \"a\") + (name2 + \"a\") + ... Dim separator() As String = {\"|\"}

I need to ha开发者_如何学Gove the following : (name1 + "a") + (name2 + "a") + ...

Dim separator() As String = {"|"}    
myString.Split(separator, StringSplitOptions.None).SomeLinq(...)

I don't know what to add at the end to add an "a" to each element...


Use Select in this case:

Dim separator() As String = {"|"}    
myString.Split(separator, StringSplitOptions.None).Select(Function(s) (s + "a"))

Select can be used as a "conversion" function this way, too. After this, you can convert back to your one string:

String.Join("|", myString.Split(separator, StringSplitOptions.None).Select(Function(s) (s + "a")).ToArray())

My apologies if the VB.Net is slightly off; I'm a C# developer, typically.


User StringBuilder and foreach()

EDIT: OOps, I don't know VB.NET, only C#, so use whatever the equivalent is of foreach

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号