F#字符串函数

/ / F#字符串函数

F#字符串连接示例

F#允许我们使用+(加号)运算符连接两个字符串。

let StringExample = 
 let s = "Hello"
 s+" "+"FSharp"
printf "%s" StringExample

输出:

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/fsharp/f-sharp-string-built-in-functions.html

来源:LearnFk无涯教程网

Hello FSharp

F#减法示例

let StringExample (s1:string):string =
 printf "%s" (s1.Substring(2))
 s1.[2..6]     //You can get substring by passing starting and ending index.
printf "%s" (StringExample "F Sharp")

输出:

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/fsharp/f-sharp-string-built-in-functions.html

来源:LearnFk无涯教程网

Sharp
Sharp

f#使用Char()方法获取给定索引的CHAR示例

let StringExample (s1:string) (index :int) = 
  s1.Chars(index)
let result = StringExample "FSharp" 5
printf "%c" result

输出:

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/fsharp/f-sharp-string-built-in-functions.html

来源:LearnFk无涯教程网

p

F#字符串比较示例

在F#中,我们可以使用equals()方法或比较(=)运算符来比较两个字符串。

let stringExample = 
  let s1:string = "hello";  
  let s2:string = "hello";  
  let s3:string = "csharp";
  printfn "%b" (s1.Equals(s2))
  printfn "%b" (s1.Equals(s3))
  printfn "%b" (s1=s2)
  printfn "%b" (s1=s3)

输出:

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/fsharp/f-sharp-string-built-in-functions.html

来源:LearnFk无涯教程网

true
false
true
false

F#字符串包含示例

The Contains () method in F# searches the specified string in the given string.

let StringExample = 
 let s1:string = "Hello FSharp"
 printfn "%b" (s1.Contains("FS"))
 printfn "%b" (s1.Contains(".Net"))

输出:

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/fsharp/f-sharp-string-built-in-functions.html

来源:LearnFk无涯教程网

true
false

F#string trim()示例

F#的Trim方法删除开始和结束空格。

let StringExample = 
 let s:string = "Hello"
 printfn "%s" (s+" FSharp")
 printfn "%s"(s.Trim()+"FSharp")

输出:

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/fsharp/f-sharp-string-built-in-functions.html

来源:LearnFk无涯教程网

Hello FSharp
HelloFSharp




祝学习愉快! (发现内容有误?请选中要编辑的内容 -> 右键 -> 修改 -> 提交!帮助我们改进教程质量)

精选教程推荐

👇 以下精选教程可能对您有帮助,拓展您的技术视野

DeepSeek 应用开发实战 -〔云阳〕

Go服务开发高手课 -〔徐逸〕

大厂设计进阶实战课 -〔小乔〕

遗留系统现代化实战 -〔姚琪琳〕

人人都用得上的写作课 -〔涵柏〕

动态规划面试宝典 -〔卢誉声〕

Web安全攻防实战 -〔王昊天〕

ZooKeeper实战与源码剖析 -〔么敬国〕

技术领导力实战笔记 -〔TGO鲲鹏会〕

📝 好记忆不如烂笔头,留下您的学习笔记吧!

暂无学习笔记,成为第一个分享的人吧!

您的笔记将帮助成千上万的学习者