none
Remove a part of string RRS feed

  • Question

  • Hi friend !

    String is 

    104065600-7000

    i want remove the part "-7000".

    please help me with this

    Friday, February 3, 2017 2:24 PM

All replies

  • I think these are all the distinct ways of accomplishing the goal.
    > let input = "104065600-7000";;
    
    val input : string = "104065600-7000"
    
    > input.Substring(0, input.Length - "-7000".Length);;
    
    val it : string = "104065600"
    
    > input.Remove(input.IndexOf("-"), "-7000".Length);;
    
    val it : string = "104065600"
    
    > input.Substring(0, input.IndexOf("-"));;
    
    val it : string = "104065600"
    
    > input.Replace("-7000", System.String.Empty);;
    
    val it : string = "104065600"
    
    > input.Split('-') |> Seq.head;;
    
    val it : string = "104065600"
    
    > new string(input |> Seq.takeWhile (fun c -> c <> '-') |> Seq.toArray);;
    
    val it : string = "104065600"
    
    Friday, February 3, 2017 8:43 PM