We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › script that sort a text on chars
Page Index Toggle Pages: 1
script that sort a text on chars (Read 633 times)
script that sort a text on chars
Jan 13th, 2010, 1:15pm
 
Hi, i'm really bussy and i probably won't sleep at all tonight.
If someone could make a script that loads a textfile and sorts all chars then that would be really great.
for example this as result:

aaaaaaaabbbbbccddddeeeeeeeeeeeeeeeffffggghhiiiijjkkkklllmmmmmnnnnnnnoooooooooppp
rrrsssssstttuuuuuvvvvvvvvwwwwwwyyzzzz
Re: script that sort a text on chars
Reply #1 - Jan 13th, 2010, 1:41pm
 
Challenge... accepted! Wink

String input = "jakhab dadkjndad";
String output = new String(sort(input.toCharArray()));
println(output);


(edit) @clankill3r : blindfish is right, don't look at the code above. you should find by yourself. huhu ^ ^
Re: script that sort a text on chars
Reply #2 - Jan 13th, 2010, 1:41pm
 
1. loadStrings().  If text file has several lines you'll need to combine them into a single string (a simple for loop should do).

2. String has a toCharArray() method (though saying that IIRC in some languages a String can be treated as an array without having to do any manipulation).  Once you have an array you can use sort()...

It's a bit cheeky to ask people to do the work for you.  How do we know the reason you're so busy is legitimate rather than poor organisation Tongue
Re: script that sort a text on chars
Reply #3 - Jan 13th, 2010, 1:42pm
 
antiplastik wrote on Jan 13th, 2010, 1:41pm:
Challenge... accepted! Wink


Sucker Tongue
Hope you didn't just do someone's homework!
Re: script that sort a text on chars
Reply #4 - Jan 13th, 2010, 1:56pm
 
Haha you're right. I've been excited by the finding-a-two-lines-of-code-solution challenge, without thinking further. Anyway, people asking for some help for bad reasons will pay... soon or later  Grin
Re: script that sort a text on chars
Reply #5 - Jan 13th, 2010, 2:37pm
 
Now I feel harsh...  I know what it's like to have to deal with deadlines and I sympathise.  It's just that sometimes it's obvious that people are asking for help with homework, often in a hurry, because they haven't done a good job of organising themselves...  In this case I'm not too sure: It may well be a legitimate cry of desperation  Shocked

Still - that's a nice and succinct solution Wink
Page Index Toggle Pages: 1