Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Exercise 3.1 – Pattern matching and recursion
- // a. Define a function vowelToUpper c that converts the characters a, e, i, o
- // and u to capitals (upper case). All other characters should be returned unchanged.
- // You are not allowed to use the standard F# method.ToUpper() on strings!
- open System
- let vowelToUpper (c:char):char=
- if (c = 'a') then 'A'
- else if (c = 'e') then 'E'
- else if (c = 'i') then 'I'
- else if (c = 'o') then 'O'
- else if (c = 'u') then 'U'
- else c
- printfn "%c" (vowelToUpper('e'))
- Console.ReadKey() |> ignore
- // b. Define another function (choose your own function name) to convert all
- // occurrences of a, e, i, o, and u in a string to capitals. Write the function to use
- // recursion and the vowelToUpper in 3.1a above
- open System
- let vowelToUpper (c:char):char=
- if (c = 'a') then 'A'
- else if (c = 'e') then 'E'
- else if (c = 'i') then 'I'
- else if (c = 'o') then 'O'
- else if (c = 'u') then 'U'
- else c
- let allVowel(s:string) = String.collect (fun c -> sprintf"%c" (vowelToUpper(c))) s
- printfn "%s" (allVowel("rohit biswas"))
- Console.ReadKey() |> ignore
Add Comment
Please, Sign In to add comment