2

I'm trying to convert string to keys from a text file and I need to split text. For example: Code c#

 string[] controls = File.ReadAllLines(FilePath);
 Keys move up = (Keys)Enum.Parse(type of(Keys),controls[1].Split("|", StringSplitOption.None), true);

In the text file at the line[1] I have : moveUp |W;

I want to set the char W as keys.

Thanks to reply and sorry if my English looks weird.

1
  • Thanks to reply, but i know about index value. I tried as you wrote bit or doesn't work, can't compile. (Can't convert "string" to "string[]") so I made another string array but i got more errors. Commented Mar 18, 2015 at 17:25

1 Answer 1

1

If you are interested in string after | , then this should be:

controls[1].Split("|", StringSplitOption.None)

replaced with this:

controls[1].Split("|")[1]

[1] means return the 2nd index value from array which will be created by Split()

If you are trying to get from Line 1 then controls[1] should be controls[0] because arrays are zero index based.

Sign up to request clarification or add additional context in comments.

2 Comments

Your solution didn't work perfectly, but it helped me to solved, replace controls[1].Split("|", StringSplitOption.None)[1] with string test = controls.Split('|')[1];
@Newokmyne edited my post , so may help others coming at this post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.