Skip to content

Commit

Permalink
fix(string): OnlyNumbers bug
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobritodev committed Aug 13, 2021
1 parent 5e4873b commit e52746b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/NetDevPack/Utilities/StringUtils.cs
Expand Up @@ -290,7 +290,7 @@ public static string OnlyNumbers(this string str)

onlyNumbers[lastIndex++] = c;
}
Array.Resize(ref onlyNumbers, onlyNumbers.Length);
Array.Resize(ref onlyNumbers, lastIndex);
return new string(onlyNumbers);
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/NetDevPack.Tests/Utilities/StringTest.cs
Expand Up @@ -27,5 +27,14 @@ public void Should_Urlize(string content, string expected)
{
content.Urlize().Should().Be(expected);
}

[Theory]
[InlineData("86456-221", "86456221")]
[InlineData("864aoeuaoeu56-221", "86456221")]
[InlineData("#@eee221oeu#@ aoeu a,34", "22134")]
public void Should_Only_Get_Numbers(string content, string expected)
{
content.OnlyNumbers().Should().Be(expected);
}
}
}

0 comments on commit e52746b

Please sign in to comment.