I have a heck of a situation here, and i'll try to explain it.
For example I have a string containing "c:\\download\\music.mp3" and I want to make it contain only music.mp3 by "filtering" away the rest. Code might seem a bit hard to understand but heres the deal. SelectedFile contains the data I want to filter so the first part reverses the text to "3pm.cisum\\daolnwod\\:c". Second part should put every letter, until a "\" appears, in SelectedFileReversed. And third, reversing SelectedFileReversed back again to "music.mp3". Problem appears at the line " SelectedFileReversed[g] = Convert.ToString(i);" and I can't understand whats wrong. I would be very greatfull for any help =)
Notice: there is a string named SelectedFileReverse and SelectedFileReversed. Try not to mix them up =)
private void SongTitle()
{
string SelectedFileReverse;
bool j = false;
//Part 1
char[] strArray = SelectedFile.ToCharArray();
Array.Reverse(strArray);
string strReversed = new string(strArray);
SelectedFileReverse = strReversed;
int g = Convert.ToInt32(0);
//Part 2
foreach (char i in SelectedFileReverse)
{
if (i != '\\' || j != true)
{
SelectedFileReversed[g] = Convert.ToString(i);
}
else
{
j = true;
}
g++;
}
//Part 3
string SelectedFileReversed2 = Convert.ToString(SelectedFileReversed);
char[] strArray1 = SelectedFileReversed2.ToCharArray();
Array.Reverse(strArray1);
string strReversed1 = new string(strArray1);
string SelectedFileTemp = strReversed;
this.lblSong.Text = SelectedFileTemp;
}