Post #109,139
7/10/03 11:14:52 PM
|
okies yankout spaces
cat foo to awk print only nonwhite space>newfilename why invoke c++? thanx. bill
questions, help? [link|mailto:pappas@catholic.org|email pappas at catholic.org]
|
Post #109,145
7/11/03 12:02:20 AM
|
Re: okies yankout spaces
I was thinking along the same lines. Isn't there a regular expression that could do that in 1 line? Something in perl? Or a call to grep with piped output?
|
Post #109,147
7/11/03 12:06:01 AM
|
In Visual BASIC 6.0 and above
there was a replace command for strings.
strName = Replace(strName," ", "")
Does C++ have a replace command like that?
"I wonder how much of this BS Corporations will continue to shallow before they start looking into alternatives to Microsoft software?" -[link|http://z.iwethey.org/forums/render/content/show?contentid=106839|Orion]
|
Post #109,191
7/11/03 8:47:25 AM
|
Nope
--
Less Is More. In my book, About Face, I introduce over 50 powerful design axioms. This is one of them.
--Alan Cooper. The Inmates Are Running the Asylum
|
Post #109,156
7/11/03 12:40:36 AM
|
s/ //g
"good ideas and bad code build communities, the other three combinations do not" - [link|http://archives.real-time.com/pipermail/cocoon-devel/2000-October/003023.html|Stefano Mazzocchi]
|
Post #109,171
7/11/03 3:43:24 AM
|
(string findTokens: ' ') inject: '' into: [:a :b | a,b]
"One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs." -- Robert Firth
|
Post #109,199
7/11/03 9:30:00 AM
|
beautiful :)
-drl
|
Post #109,249
7/11/03 12:27:20 PM
|
Doh! Better: string select: [:ea | ea ~= $ ]
What was I thinking? Must have been later than I thought
"One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs." -- Robert Firth
|
Post #109,333
7/11/03 7:08:42 PM
|
Or maybe (string copyWithout: $ )
This is sort of a fun little exercise actually - I don't think in Smalltalk enough.
Smalltalk is dangerous. It is a drug. My advice to you would be don't try it; it could ruin your life. Once you take the time to learn it (to REALLY learn it) you will see that there is nothing out there (yet) to touch it. Of course, like all drugs, how dangerous it is depends on your character. It may be that once you've got to this stage you'll find it difficult (if not impossible) to "go back" to other languages and, if you are forced to, you might become an embittered character constantly muttering ascerbic comments under your breath. Who knows, you may even have to quit the software industry altogether because nothing else lives up to your new expectations. --AndyBower
|
Post #109,192
7/11/03 8:50:08 AM
|
Right before he left, he tried to rally in Perl
\nsub removeSpaces {\n my $s= "aa bb";\n print $s\n $s =~ s/ //gi;\n print $s\n}\n\n$s = "aa bb";\nremoveSpaces;\n
--
Less Is More. In my book, About Face, I introduce over 50 powerful design axioms. This is one of them.
--Alan Cooper. The Inmates Are Running the Asylum
|
Post #109,233
7/11/03 11:44:47 AM
|
He might have been better at C++
"good ideas and bad code build communities, the other three combinations do not" - [link|http://archives.real-time.com/pipermail/cocoon-devel/2000-October/003023.html|Stefano Mazzocchi]
|
Post #109,178
7/11/03 7:00:51 AM
|
Perl
my $nospaces = join('',split(/ /,$withspaces));
C++? What an ODD way to make a living...
Peter [link|http://www.debian.org|Shill For Hire] [link|http://www.kuro5hin.org|There is no K5 Cabal] [link|http://guildenstern.dyndns.org|Blog]
|
Post #109,228
7/11/03 11:29:51 AM
|
Perl redux
perl -p -i -e 's/ //g'
----- Steve
|
Post #109,242
7/11/03 12:02:24 PM
|
sed 's/ //g' filename.txt > filename2.txt
I mean if we're really going for minimal, right? :)
===
Implicitly condoning stupidity since 2001.
|
Post #109,246
7/11/03 12:18:59 PM
|
key difference, though.
The perl command will edit the file in place versus having sed read the original file from stdin and write a new file to stdout :)
----- Steve
|
Post #109,231
7/11/03 11:39:48 AM
7/11/03 11:40:45 AM
|
Java
StringBuffer a = new StringBuffer( " ab ab ab ab " );
for( int i=0; i < a.length(); ) { if ( a.charAt(i) == ' ' ) a.deleteCharAt(i); else i++; // only increment if you don't delete char }
Edited by gdaustin
July 11, 2003, 11:40:45 AM EDT
|
Post #109,251
7/11/03 12:32:06 PM
|
Wow, that's a lot of typing :-P
"One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs." -- Robert Firth
|
Post #109,268
7/11/03 1:13:42 PM
7/11/03 1:14:15 PM
|
n^^2 for the worst case
can you do better? May be not in Java - I have to look at StringBuffer
--
Less Is More. In my book, About Face, I introduce over 50 powerful design axioms. This is one of them.
--Alan Cooper. The Inmates Are Running the Asylum
Edited by Arkadiy
July 11, 2003, 01:14:15 PM EDT
|
Post #109,269
7/11/03 1:16:12 PM
|
Yes you can
--
Less Is More. In my book, About Face, I introduce over 50 powerful design axioms. This is one of them.
--Alan Cooper. The Inmates Are Running the Asylum
|
Post #109,290
7/11/03 2:13:16 PM
|
You're looking for "best algorithm"
I was looking for compact code, quick implementation.
Sadly, a lot of the work I have to do is done in a hurry, so the customer doesn't care if it's a bubble sort or quick/merge/insert sort unless the data set is really large.
Also, I work with databases a lot, so when someone wants it sorted, I ORDER BY on the SQL and it's done.
DB2 SQL is my best language. Java is probably next.
I haven't looked for the "best algorithm" since I worked at SABRE, where we had lots of time (usually at least 2 quarters) to implement something.
Glen Austin
|
Post #109,299
7/11/03 2:32:22 PM
|
Re: Java - off the top of my head...
\nStringBuffer a = new StringBuffer( " ab ab ab ab " );\n\nint j = 0;\nint i = 0;\nwhile (i < a.length())\n {\n while (i < a.length() && a.charAt(i) == ' ' ) // Change this to a while\n // a.deleteCharAt(i); Don't delete\n i++;\n if (i < a.length())\n {\n a.charAt(j) == a.charAt(i); // Pull the characters forward.\n i++; // walk both forward\n j++;\n }\n }\n Yeah...you need to clean the code up at the end too....but hey...it's off the top of me head. (And I'm sure it can be improved.)
|