Newokmyne
Newokmyne

Reputation: 65

Split string from text file

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.

Upvotes: 2

Views: 972

Answers (1)

Ehsan Sajjad
Ehsan Sajjad

Reputation: 62488

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.

Upvotes: 1

Related Questions