Raised This Month: $51 Target: $400
 12% 

[REQ] new stock "strip_newline"


  
 
 
Thread Tools Display Modes
Author Message
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 09-07-2006 , 20:50   [REQ] new stock "strip_newline"
#1

Code:
stock strip_newline(strip[])
{
 new len = strlen(strip)
 if (len <= 0) return
 if (strip[len]-1 == '^n') strip[--len] = 0
}
or something to that effect. Would come in handy esp for coders who are afraid of the fancy new file natives because of different things like the newline that is in the string.
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
BAILOPAN
Join Date: Jan 2004
Old 09-08-2006 , 03:58   Re: [REQ] new stock "strip_newline"
#2

wouldn't it be easier to just use trim()?
__________________
egg
BAILOPAN is offline
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 09-08-2006 , 06:51   Re: [REQ] new stock "strip_newline"
#3

I didn't know trim removed newlines?
When the new file natives came out I remember in an examples post or a changes post there was an example of how to remove the newline, and it wasn't just "trim".
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
BAILOPAN
Join Date: Jan 2004
Old 09-08-2006 , 07:18   Re: [REQ] new stock "strip_newline"
#4

it removes whitespace and newlines are definitely whitespace.

the example was typical of my own parsing routines in C which take off the end newline but don't remove excess whitespace. it was probably a poor example.

but if you're using the C-based file natives rather than read_file(), it usually means you're writing your own optimized parser. the stock isn't as useful as it is inlined - the inlined version maintains the string length so you don't need to make extra calculations or multiple calls to strlen().

so, my feeling is that this is best left to the programmer, as long as the notice in the include is helpful.
__________________
egg

Last edited by BAILOPAN; 09-08-2006 at 07:23.
BAILOPAN is offline
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 09-08-2006 , 19:31   Re: [REQ] new stock "strip_newline"
#5

yeah sounds good, didn't know trim would do it. Might not be a bad idea to mention that in the file include.
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
 



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


All times are GMT -4. The time now is 04:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode