![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
gay SPLIT() function
here is my code:
[php] public string[] ReadFile(string tempInFile) { string s_inLine=null; string[] s_inLineArray=new string[15]; char[] c_delimArray=new Char[] {'|'}; using(inFile=new StreamReader(tempInFile)) { s_inLine=inFile.ReadLine(); if(s_inLine.Substring(1,2)=="IG" || s_inLine.Substring(1,2)=="BW") { inFile.Close(); return ReadOldFile(tempInFile); } s_inLineArray=s_inLine.Split(c_delimArray); } return s_inLineArray; } public string[] ReadOldFile(string tempOldFile) { string s_inLine=null; string[] s_inLineArray=new string[15];//,s_tempSeperater=new string[2]; char[] c_delimArray=new Char[] {'^'}; using(inFile=new StreamReader(tempOldFile)) { s_inLine=inFile.ReadToEnd(); s_inLineArray=s_inLine.Split(c_delimArray); } return s_inLineArray; } [/php] when i use a .split why the HELL does is count a CR/LF as a delimeter... or why the hell does it through that section into its own element? Im telling it to split with a pipe delimeter... or the carrot! I only want each of those |fields| ^fields^ to be thrown into there own element. PLEASE tell me there is a way to avoid looking at CR/LF as a delimeter?
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#2 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
On an unrelated note, isn't a little silly to garbage collect a 15 element string array without using it?
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#3 |
|
Expert Programmer
|
i use it... ??? you mean s_inLineArray? if you look a littler closer.. it is being returned and used in a different section of code.
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#4 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#5 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 646
Rep Power: 4
![]() |
Please avoid the use of gay to denote something that is stupid. No, I am not gay, but the comparison is incredibly offensive.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#6 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Arrays are reference-type.
string[] s_inLineArray=new string[15]; s_inLineArray=s_inLine.Split(c_delimArray); The array originally referred to by s_inLineArray no longer has any references and is garbage collected. I point this out because it is a common misconception when transitioning from C or C++. Or just about any lower level language for that matter.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#7 |
|
Expert Programmer
|
ok so i should not use:
[php] string[] s_inLineArray=new string[15]; [/php] and i should use: [php] string[] s_inLineArray; [/php] because the split function will create a specified amount of elements upon calling the function? And do you know the anwser to my original question with the CR/LF?
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#8 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
The msdn page hints in the remarks section that Split enjoys to eat newlines as delimiters without asking. You can work around that behavior with your own split method OR...
1. Split the file contents by newlines 2. Split each element of the result array by pipes/carets 3. Combine the results of step 2 into a single array
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#9 |
|
Expert Programmer
|
DATA FILE:
[php] "IG^68593-03^Dealer Power Reactivation^68593-03[A-D].txt^Job Ticket^[None]^iGen Number^XMPI^Steve Shanafelt^Account = DME Campaign = Dealer Power UAPM Document = RA2.indd Samples = 68593-03sam_sorted.txt^True^False^Custom (Type in Measurements)^6.0^20.0^Landscape^1x2^Duplex HTH Rotated^True^True^0.25^0.0" [/php] i need each field in between the carrots in its own element of the array. One of the fields happens to be contents of a multiline text box causing the new lines? Although your solution would work in general. For my problem i might need to address it differently?
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|