String Copy with parameters

Is there a function in c# which copies a string like so:

two integers

int x = 0;
int y = 2;

string test = "whatever";

i want to copy like so:

string one = test(x, y) where x is the starting character and y is the ending character so in this example one would be "wha".

then I want to change x and y

x = 3;
y = 7;

string two = test(x, y) would result in "tever"

The buit in substring function either takes two indexes and copies from first index trough the second index, or one index and copies from begining to the end of the string.  I want to be able to specify the beginning and ending indexes.  Thank you very much.
nstefanovAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ennixoCommented:
no but you can make your method :

public string SubString2(string originalString, int startIndex, int endIndex)
{
    return originalString.SubString(startIndex, endIndex - startIndex);
}

very easy.
AlexFMCommented:
Existing Substring function has (startIndex, length) parameters. You can write your own function:

string MySubstring(string s, int startIndex, int endIndex)
{
    return s.Substring(startIndex, endIntex - startIndex + 1);
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bruintjeCommented:
Hello nstefanov,

the substring is indeed only using starting index and length, but from your description you might do something like

int x = 0;
int y = 2;

string test = "whatever";
string one = test(x, y - x + 1); // results in "wha"

x = 3;
y = 7;

string two = test(x, y - x + 1); // results in "tever"

hope this helps a bit
bruintje
bruintjeCommented:
shouldn't type that much :)
bruintjeCommented:
string one = test.substring(x, y - x + 1); // results in "wha"
string two = test.substring(x, y - x + 1); // results in "tever"
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.