Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

asEnumerable for strings #21

Closed
pilotgeraldb opened this issue Apr 18, 2018 · 1 comment
Closed

asEnumerable for strings #21

pilotgeraldb opened this issue Apr 18, 2018 · 1 comment
Assignees

Comments

@pilotgeraldb
Copy link
Owner

Since a string is an array of characters, it would helpful to provide the asEnumerable() extension method for strings as well. This method would create an array of characters via the following:

var arr = [];

for(var i = 0; i < str.length; i++)
{
    arr[i] = str.charAt(i);
}

You could then have access to any of the asEnumerable functions (any, count, select, where.. etc).

var str = "abcdef";
str.asEnumerable().dropLast(4);
//result: "ab"

After which it becomes necessary to seamlessly convert back to a string. This could be accomplished by overriding the toString() method of the array that is created when asEnumerable() is called.

var arr = ["a", "b"];
var result = arr.join('');
// result: "ab"

This would allow syntax like str.asEnumerable().dropLast(3).toString() 😄

@pilotgeraldb
Copy link
Owner Author

this didnt really go as planned when implementing toString()

var result = arr.join('');

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant