C# - Substring problem

Associate
Joined
14 Jan 2010
Posts
1,192
Location
Northern Ireland
Trying to shorten a string.

Code:
            string[] Files = Directory.GetFiles(path, "*.SAV");
            foreach (string s in Files)
            {
                s.Substring(30, 10);
                listView1.Items.Add(s);
            }

But it doesn't actually change the string at all for some reason, help?
 
You need to assign the result of s.Substring to a variable, or use it directly in the call to the Add method.

Either:
Code:
string shortString = s.Substring(30, 10);
listView1.Items.Add(shortString);

Or:
Code:
listView1.Items.Add(s.Substring(30, 10));
 
Back
Top Bottom