microsoft/BosqueLanguage

How do I check if a string contains a substring?

Closed this issue · 3 comments

Xh4H commented

Topic.

I've tried:

var test = "a";
var contains = test.includes("a");

But that errors... So... any ideas?

That's happening because test variable is a String[T] but includes method is expecting non-generic String.

Here's an example to demonstrate:

namespace NSMain;

function stringTest(str: String): Bool {
    return true;
}

function stringTest2(str: String[T]): Bool {
    return true;
}

entrypoint function main(): Bool {
    var test = "Test";

    //return stringTest(test); // This will throw exception.
    //return stringTest2(test); // This is OK.
}

I'll make a PR request which should fix the issue.

Hi, I was actually just working on this as well and opened PR #114 which should fix it (will add some tests and update it in a minute). @clegoz, you were right about where to problem was coming from, please take a look and review if you are interested.

Xh4H commented

Alright thank you