| | |
Array problem
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2005
Posts: 13
Reputation:
Solved Threads: 0
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 =)
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 =)
C# Syntax (Toggle Plain Text)
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; }
•
•
Join Date: Jul 2005
Posts: 483
Reputation:
Solved Threads: 19
here, same result in 4 lines
C# Syntax (Toggle Plain Text)
private void SongTitle() { char[] strArray = SelectedFile.ToCharArray(); string result; = new string(strArray); string[] strArray = result.Split('\\'); this.lblSong.Text = strArray[(strArray.Length - 1)] }
Last edited by campkev; May 10th, 2006 at 6:45 pm. Reason: fixed code tags
![]() |
Similar Threads
- Array problem (Java)
- Array problem (C++)
- Is there a simplest way to work this array problem? (C++)
- class array problem! (C++)
- C++ help with student array problem (C++)
- i have problem with array plz help (Java)
- Large Array Problem (PHP)
Other Threads in the C# Forum
- Previous Thread: Monitoring registry additions
- Next Thread: Pictures in RichTextBox
| Thread Tools | Search this Thread |
.net access algorithm array backup barchart bitmap box broadcast buttons c# check checkbox client clock combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees developer development draganddrop drawing dynamiccreation encryption enum excel file form format forms function gdi+ hospitalmanagementsystems httpwebrequest image index input install interface java label list listbox mandelbrot math microsystems mouseclick mysql operator password path photoshop picturebox pixelinversion post priviallages. programming property radians regex remoting richtextbox running... serialization server sleep soap socket sql sqlserver stack statistics stream string table temperature text textbox thread time timer update usercontrol validation visualstudio webbrowser windows windowsformsapplication winforms wpf write xml






