Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 7th, 2008, 11:03 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default string.Split Oddity

What's going on here?

Code:
string foo = "";
int i = foo.Split(new char[] {'*'}).Length;
The value of i is 1. Is this a bug or am i missing something?
__________________
http://www.thewebsiteshop.co.uk
  #2 (permalink)  
Old August 7th, 2008, 12:19 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

No, this is not a bug. As far as the Split method is concerned, you have 1 zero length string in foo. If you made foo = "," you would have 2 zero length strings. You can tell the Split method to remove empty elements, it's the second parameter to the method (System.StringSplitOptions). This should then return a zero element array for an empty string.

-Peter
compiledthoughts.com
  #3 (permalink)  
Old August 9th, 2008, 03:32 PM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Peter, much appreciated.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to split string krevathi1912 Access VBA 10 September 6th, 2007 02:21 AM
string split vidhya XSLT 1 August 10th, 2005 04:53 AM
How to split a string lily611 General .NET 5 March 18th, 2005 01:16 PM
string split by : crmpicco Classic ASP Basics 3 February 10th, 2005 07:49 AM



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


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.