Click here to Skip to main content
15,881,882 members
Home / Discussions / C#
   

C#

 
AnswerRe: split method bug Pin
PIEBALDconsult22-Sep-17 2:51
mvePIEBALDconsult22-Sep-17 2:51 
GeneralRe: split method bug Pin
WoodChuckChuckles22-Sep-17 2:56
WoodChuckChuckles22-Sep-17 2:56 
AnswerRe: split method bug Pin
Richard MacCutchan22-Sep-17 3:44
mveRichard MacCutchan22-Sep-17 3:44 
GeneralRe: split method bug Pin
WoodChuckChuckles22-Sep-17 5:43
WoodChuckChuckles22-Sep-17 5:43 
GeneralRe: split method bug Pin
Richard MacCutchan22-Sep-17 5:56
mveRichard MacCutchan22-Sep-17 5:56 
GeneralRe: split method bug Pin
eddieangel22-Sep-17 6:42
eddieangel22-Sep-17 6:42 
GeneralRe: split method bug Pin
WoodChuckChuckles22-Sep-17 7:56
WoodChuckChuckles22-Sep-17 7:56 
GeneralRe: split method bug Pin
eddieangel22-Sep-17 8:13
eddieangel22-Sep-17 8:13 
It was a bit of hyperbole. Any time you are parsing string data you want to understand what possible user inputs could cause you problems and make sure your string is scrubbed before you split it. If there is a possibility of newline characters, carriage returns, or inconsistent tabs you want to address those. The simple solution is a string replace, there are more advanced strategies using regular expressions and such. But in favor of simplicity try something like this:

class Program
    {
        static void Main(string[] args)
        {
            string CurrentLine; // Remove this, it isn't necessary
            string FilePath = "C:\\12837.SDF.txt"; // Change this to filePath, it is the generally correct way of naming method level variables
            using (StreamReader sr = new StreamReader(FilePath)) // change to filePath also
            {
                while(!sr.EndOfStream)
                {
                    string currentLine = sr.ReadLine();
                     GetSplit(currentLine.Replace("\t","").Replace("\r","").Replace("\n","");
                   // Console.WriteLine(array.Length.ToString());
 
                }
            }
        }
 
        private static void GetSplit(string CurrentLine)
        {
            string[] array = CurrentLine.Split(';');
            string first = array[0];
            string second = array[1];
            string third = array[2];
            string four = array[3];
          //  string five = array[4];
           // string six = array[5];
          //  string seven = array[6];
           // string eight = array[7];
            Console.WriteLine(first + " " + second + " " + third + " " + four);
        }
    }
}


That is just a general idea on how to handle it. One thing you always want to be wary of is bad input, and the best way to deal with it is to aggressively control your strings by stripping out troublesome characters.
QuestionI wants to show a stack panel using the TextBlock controls for the MyNotes about box. Which of the following code will help for me ? Pin
Member 1309368222-Sep-17 0:19
Member 1309368222-Sep-17 0:19 
AnswerRe: I wants to show a stack panel using the TextBlock controls for the MyNotes about box. Which of the following code will help for me ? Pin
OriginalGriff22-Sep-17 0:53
mveOriginalGriff22-Sep-17 0:53 
AnswerRe: I wants to show a stack panel using the TextBlock controls for the MyNotes about box. Which of the following code will help for me ? Pin
Pete O'Hanlon22-Sep-17 2:09
mvePete O'Hanlon22-Sep-17 2:09 
QuestionI wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
Member 1309368221-Sep-17 22:59
Member 1309368221-Sep-17 22:59 
AnswerRe: I wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
Eddy Vluggen21-Sep-17 23:15
professionalEddy Vluggen21-Sep-17 23:15 
AnswerRe: I wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
OriginalGriff21-Sep-17 23:18
mveOriginalGriff21-Sep-17 23:18 
AnswerRe: I wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
Jochen Arndt22-Sep-17 0:17
professionalJochen Arndt22-Sep-17 0:17 
GeneralRe: I wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
Rob Philpott22-Sep-17 0:19
Rob Philpott22-Sep-17 0:19 
GeneralRe: I wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
Jochen Arndt22-Sep-17 0:23
professionalJochen Arndt22-Sep-17 0:23 
GeneralRe: I wants to convert a string to an array of bytes using UTF-8 encoding and write it to a file, which of the following code should be use ? Pin
Rob Philpott22-Sep-17 1:15
Rob Philpott22-Sep-17 1:15 
QuestionImplementing a COM Message Filter, it always fails... Pin
Joan M21-Sep-17 5:57
professionalJoan M21-Sep-17 5:57 
SuggestionRe: Implementing a COM Message Filter, it always fails... Pin
Richard Deeming21-Sep-17 6:14
mveRichard Deeming21-Sep-17 6:14 
GeneralRe: Implementing a COM Message Filter, it always fails... Pin
Joan M21-Sep-17 6:21
professionalJoan M21-Sep-17 6:21 
GeneralRe: Implementing a COM Message Filter, it always fails... Pin
Richard Deeming21-Sep-17 6:37
mveRichard Deeming21-Sep-17 6:37 
GeneralRe: Implementing a COM Message Filter, it always fails... Pin
Joan M21-Sep-17 7:26
professionalJoan M21-Sep-17 7:26 
QuestionEntity Framework Questions - Round 1 Pin
Kevin Marois21-Sep-17 4:11
professionalKevin Marois21-Sep-17 4:11 
AnswerRe: Entity Framework Questions - Round 1 Pin
Nathan Minier21-Sep-17 4:46
professionalNathan Minier21-Sep-17 4:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.