F# 将用户名与电子邮件分开
F# separating username from email
我需要执行将用户名与电子邮件分开的功能。变量名称中有用户名,但我不知道如何 return 它。
let rec email (a:string) =
let rec loop i (name:string)=
if a[i] <> '@' then loop (i+1) (name+a[i].ToString())
loop 0 ""
let rec email (a:string) =
let rec loop i (name:string)=
if a[i] <> '@' then loop (i+1) (name+a[i].ToString())
else name
loop 0 ""
这里是使用 built-ins
的实现
let email (a: string) =
a
|> Seq.takeWhile (fun c -> c <> '@')
|> Seq.toArray
|> System.String
我需要执行将用户名与电子邮件分开的功能。变量名称中有用户名,但我不知道如何 return 它。
let rec email (a:string) =
let rec loop i (name:string)=
if a[i] <> '@' then loop (i+1) (name+a[i].ToString())
loop 0 ""
let rec email (a:string) =
let rec loop i (name:string)=
if a[i] <> '@' then loop (i+1) (name+a[i].ToString())
else name
loop 0 ""
这里是使用 built-ins
的实现let email (a: string) =
a
|> Seq.takeWhile (fun c -> c <> '@')
|> Seq.toArray
|> System.String