Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 27th, 2006, 9:11 PM   #1
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
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
Kilo is offline   Reply With Quote
Old Feb 27th, 2006, 9:17 PM   #2
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
On an unrelated note, isn't a little silly to garbage collect a 15 element string array without using it?
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Feb 27th, 2006, 9:19 PM   #3
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
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
Kilo is offline   Reply With Quote
Old Feb 27th, 2006, 9:24 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
pipe delimeter... or the carrot!
Always woiked fer me, wit' da mule.
__________________
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
DaWei is offline   Reply With Quote
Old Feb 27th, 2006, 9:33 PM   #5
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 646
Rep Power: 4 Jessehk is on a distinguished road
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!
Jessehk is offline   Reply With Quote
Old Feb 27th, 2006, 10:00 PM   #6
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Arrays are reference-type.

string[] s_inLineArray=new string[15];
...creates an array of 15 null pointers to strings. The array itself is an object.

s_inLineArray=s_inLine.Split(c_delimArray);
...changes the reference named "s_inLineArray" to an entirely different array returned by the split method.

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
Dameon is offline   Reply With Quote
Old Feb 27th, 2006, 10:05 PM   #7
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
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
Kilo is offline   Reply With Quote
Old Feb 27th, 2006, 10:18 PM   #8
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
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
Dameon is offline   Reply With Quote
Old Feb 27th, 2006, 10:30 PM   #9
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
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
Kilo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:20 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC