Page 1 of 1 |
|
|
Back to top |
|
 |
|
Posted: Thu, 22nd Jul 2010 04:10 Post subject: |
|
 |
You should try doing basic math in scheme before you complain about "ridiculous" code.
And I can't think of anything you can really do to compact that. You can't get rid of any arguments or anything. Perhaps if you're splitting strings exactly the same way a lot you could make a small method that returns the split string and then just call that method instead of writing out all that.
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 73238
Location: Ramat HaSharon, Israel 🇮🇱
|
Posted: Thu, 22nd Jul 2010 14:17 Post subject: |
|
 |
There is also Regex.Split(str, ",") but I can't find anything to remove empty entries...
|
|
Back to top |
|
 |
garus
VIP Member
Posts: 34197
|
Posted: Thu, 22nd Jul 2010 15:32 Post subject: |
|
 |
snip
Last edited by garus on Tue, 27th Aug 2024 21:27; edited 1 time in total
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 73238
Location: Ramat HaSharon, Israel 🇮🇱
|
Posted: Thu, 22nd Jul 2010 23:41 Post subject: |
|
 |
garus wrote: | PS. Every language I use reminds of how awsome Ruby is
Same thing in Ruby:
Code: |
text = "some, kind, of text, here"
puts text.split(',').delete("").first
|
 |
You can do exactly the same in C#:
Code: | var test = "123,456,,789";
var results = test.Split(',').Where(str => str != "").First(); |
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
garus
VIP Member
Posts: 34197
|
Posted: Thu, 22nd Jul 2010 23:44 Post subject: |
|
 |
snip
Last edited by garus on Tue, 27th Aug 2024 21:27; edited 1 time in total
|
|
Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 73238
Location: Ramat HaSharon, Israel 🇮🇱
|
Posted: Thu, 22nd Jul 2010 23:48 Post subject: |
|
 |
Could even improve it to:
Code: | var result = test.Split(',').Where(str => str.Trim() != "").First(); |
This will take care of cheeky results like "123, ,234". 
|
|
Back to top |
|
 |
|
Posted: Fri, 23rd Jul 2010 03:01 Post subject: |
|
 |
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |