[F#] How do I manipulate strings in F# (e.g., concatenation, length)?

In F#, you can manipulate strings using the following methods:

  1. Concatenation: You can concatenate strings using the + operator or the ^ operator.
1let str1 = "Hello"
2let str2 = "World"
3let result1 = str1 + " " + str2 // "Hello World"
4let result2 = str1 ^ " " ^ str2 // "Hello World"
  1. Length: You can get the length of a string using the String.length function.
1let str = "Hello World"
2let length = String.length str // 11
  1. Accessing characters: You can access individual characters in a string using indexing.
1let str = "Hello World"
2let firstChar = str.[0] // 'H'
3let thirdChar = str.[2] // 'l'
  1. Substring: You can extract a substring from a larger string using the Substring method.
1let str = "Hello World"
2let subStr = str.Substring(6, 5) // "World"
  1. Splitting strings: You can split a string into an array of substrings using the Split method.
1let str = "Hello,World"
2let substrings = str.Split(',') // [| "Hello"; "World" |]
  1. String interpolation: You can interpolate values into a string using the sprintf function.
1let name = "John"
2let age = 30
3let message = sprintf "My name is %s and I am %d years old." name age // "My name is John and I am 30 years old."

These are just some of the basic string manipulation operations in F#. There are many more advanced methods and functions available in the F# String module and additional libraries that you can explore based on your requirements.