Talk:Trimming (computer programming)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computer science  
WikiProject icon This article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
 ???  This article has not yet received a rating on the project's quality scale.
 ???  This article has not yet received a rating on the project's importance scale.
 

C/C++ example needs actual code[edit]

The C/C++ example isn't too illustrative of the theory behind trimming a string in C. Perhaps an example that contains the actual code would be more appropriate. (I want to see some loops in there!) --indil 20:55, 19 July 2006 (UTC)

I went for a brief overview and stuck with the simplest functions/libraries/implementations I could find. Please feel free to add some code :) —Pengo talk · contribs 13:02, 23 July 2006 (UTC)
I've changed the code for the C example. I believe the old example would have leaked memory - for processing large amounts of data, this could cause problems! On a side note, could someone check to make sure I haven't done something dumb while writing this (it compiled and worked in VC++) --Portej 07:29, 26 September 2007 (UTC)
At least for me the example in C does NOT work. i doubled checked it, but still believe, that i did not make a mistake. the problematic section is shown below. this causes a segmentation fault in my environment (gcc-4.1.3). --Alex.blackbit 18:32, 1 November 2007 (UTC)
if (last != input)
    last[1] = 0;
Alex, this is with strings that don't need trimming? Yeh, last should have been initialized with ret before the loop. I'm fine with just dropping the code though, if it wasn't just a line count thing. James Antill 16:03, 6 November 2007 (UTC)

in AWK better to use those command:

function ltrim(s) { sub(/^ */, "", s); return s }

function rtrim(s) { sub(/ *$/, "", s); return s }

function trim(s) { return rtrim(ltrim(s)); }

Keep the functions. Remove just code[edit]

Hi, I think you should remove the "other languages which don't have trim functions" section. They don't have trim or a close analogue, so they should be trimmed. It is superfluous text at the end of the article that happens to take up more than half the article that is supposed to be on trim rather than what is not trim. It is quite easy to define trim-like and, by omision what is not trim-like. That section becomes a tutorial on how to write trim in other languages and should be removed or moved to this talk page. Please refer to this. --Paddy 05:32, 10 October 2007 (UTC)

It's about trim library functions as well as trim algorithms. Most of the examples (except C) are only one or two lines of code (which is probably why they don't have library functions). Hardly a hand-holding instruction manual. Leaving them out is to pretend trimming isn't used in these languages, and removes much of the language-specific discussion. Lastly, the code certainly doesn't belong on the talk page. —Pengo 14:26, 10 October 2007 (UTC)
I see what you mean about the short examples, and also not transferring them to the talk pages, but that large chunk of C? Surely that should go. --Paddy 15:32, 10 October 2007 (UTC)
Yep, probably. Would be nice to move it to Wikibooks, or at least include a link to an open source implementation of the same thing though. —Pengo 06:09, 11 October 2007 (UTC)
The only point is that if that trim function was used on a large dataset, with lots of whitespace, it would leak memory at a heck of a rate. Is there anywhere that implementations can go? (someone mentioned wikibooks) —Preceding unsigned comment added by 203.59.18.181 (talk) 14:37, 17 October 2007 (UTC)
I dropped the line count significantly on the C example, and it now doesn't allocate memory. Both of which make it much more likely to resemble a real implementation IMO. --James Antill 05:32, 19 October 2007 (UTC)
Thanks, it is more succinct, but the point remains that the C function is showing how to write trim in C which does not have trim. Best to leave it out and rely on the mention of external libraries that give trim functionality as a package. --Paddy 18:04, 19 October 2007 (UTC)
I've re-removed the C function, as it seems to be a perennial problem. The other code in the article is well established and used frequently in copy/paste programming. I don't think Wikipedia is the best environment to write new code. It could even be seen as "original research". —Pengo 01:08, 2 November 2007 (UTC)

SAS has a trimmed TRIM[edit]

the SAS language has a STRIP function, but this only removes the space (ASCII 0x20) characters, not all whitespace. —Preceding unsigned comment added by 165.155.110.5 (talk) 14:32, 8 February 2011 (UTC)