Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

It seems that String in OCaml has only index of a char, not a substring.

Question:

How can I easily get the index of a substring in OCaml?

What's the best library to do string searching/manipulation in OCaml?

share|improve this question

1 Answer

up vote 1 down vote accepted

But Str has:

let _ =
    let s = "foo bar string" in
    let reg = Str.regexp_string "bar" in
    print_int (Str.search_forward reg s 0)

The result is 4;

share|improve this answer
what module or library I should download for Str? – Jackson Tale 8 mins ago
File "none", line 1: Error: No implementations provided for the following modules: Str referenced from test/test_fs.cmx Command exited with code 2. Compilation unsuccessful after building 8 targets (4 cached) in 00:00:00. – Jackson Tale 5 mins ago
ok, got it. should link package str – Jackson Tale 1 min ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.