xiaoguang
(xiaoguang)
February 6, 2019, 2:54am
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.
ck
(Carlo Kok)
February 6, 2019, 5:48am
2
Which platform is this? Depending on the platform you have to import the right linq namespace and then it ought to work.
xiaoguang
(xiaoguang)
February 6, 2019, 6:08am
3
I am using the .net platform and the linq namespace is already imported:
ck
(Carlo Kok)
February 6, 2019, 12:06pm
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
(joseasl)
February 6, 2019, 12:24pm
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.
mh
(marc hoffman)
February 6, 2019, 12:40pm
6
Looks like RTL2 String isn’t a sequence right now. will fix. Meanwhile, workaround is to cast to System.String, if needed. thanx!
Thanks, logged as bugs://81903
bugs://E22550 was closed as fixed.