How to do Linq in silver?


(xiaoguang) #1

Hello,

I have the following C# code and want to convert to Swift:

public static string Dosomething(string input)

    {

        string output = new string(input.Where(c => !char.IsControl(c)).ToArray());
        return output;

    }

Using the convert function:

public static func Dosomething(_ input: String!) -> String! {
var output: String! = String(input.Where({ © in
!AnsiChar.IsControl©
}).ToArray())
return output
}

The compiler says:

No member “Where” on type "String!
No static member “IsControl” on type “AnsiChar”

So what is the correct way to do it in silver?

Also, is it possible to do linq using Remobject RTL so that have better code-reused?

Thank you.


(Carlo Kok) #2

Which platform is this? Depending on the platform you have to import the right linq namespace and then it ought to work.


(xiaoguang) #3

I am using the .net platform and the linq namespace is already imported:


(Carlo Kok) #4
import System.Collections.Generic
import System.Linq
import System.Text
import System.Threading.Tasks


print("The magic happens here.")

public static func DoSomething(_ input: String!) -> String! {
    var output: String! = String(input.Where {c in !Char.IsControl(c) }.ToArray())
    return output
}

this works fine. What am I missing?


(joseasl) #5

Looks like there is some conflict with RemObjects.Elements.RTL
If you create a console application in VS, it doesn’t adds RemObjects.Elements.RTL to the default uses clause. Water adds it. You can try to add import RemObjects.Elements.RTL and it will fail.


(marc hoffman) #6

Looks like RTL2 String isn’t a sequence right now. will fix. Meanwhile, workaround is to cast to System.String, if needed. thanx!


(RemObjects) #7

Thanks, logged as bugs://81903