Arachnid / solidity-stringutils

Basic string utilities for Solidity
Apache License 2.0
1.12k stars 369 forks source link

Unwanted empty string in split function #34

Closed samanshahmohamadi closed 5 years ago

samanshahmohamadi commented 5 years ago

Hi I'm trying to split a string like this: hellow-world-how-are-you-doing with the code below.

var s = c.toSlice();
var delim = "-".toSlice();
var parts = new string[](s.count(delim) + 1);
string[] memory arr = new string[](parts.length);
for (uint i = 0; i < parts.length; i++) {
      arr[i] = (s.split(delim).toString());
}

But when running a test with truffle there is always an unwanted extra empty string in the result array. This is weird but it's working just fine in remix-ide.

samanshahmohamadi commented 5 years ago

This is due to a known bug in web3js and is nothing related to this library.