Click here to Skip to main content
15,922,166 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Well, i want to make a function that gets the first result from a array of strings formatted like so:
a=q
b=t
c=5
d=7

I'm using CRLF so its \r\n
Also in the code below, i have a swap feature so that you can also get the first result that ENDS (instead of starts) with whatever. (that's the swap property)
The function returns �

What I have tried:

this
C#
private string GetFromArray(string a, string[] b, bool swap)
    {
        Console.WriteLine(String.Join("\\r\\n", b));
        for (int c = 0; c > b.Length; c++)
        {
            string d = b[c];
            if (!swap)
            {
                if (d.StartsWith(a))
                {
                    return d.Replace(a + "=", "");
                }
            }
            else
            {
                if (d.EndsWith(a))
                {
                    return d.Replace("=" + a, "");
                }
            }
        }
        return "�";
    }

    private string Get(string e, bool swap)
    {
        StreamReader q = new StreamReader(LangFile);
        string txt = q.ReadToEnd();
        q.Close();
        char[] a = { '\r' };
        string[] t = txt.Split(a);
        return GetFromArray("a", t, swap);
    }
Posted
Updated 25-Jun-21 17:17pm
v2
Comments
Richard MacCutchan 26-Jun-21 8:12am    
I just tried this and it works fine.

1 solution

Using the debugger would have should your mistake in a few seconds.
C#
for (int c = 0; c > b.Length; c++)
{                 ^
                  |
                  +---This should be less-than

The loop will execute so long as the condition is true. Since 0 is never greater than the Length of the array, the loop will never execute.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900