Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 7th, 2008, 11:03 AM
Authorized User
 
Join Date: Dec 2006
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
 
Old August 7th, 2008, 12:19 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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
 
Old August 9th, 2008, 03:32 PM
Authorized User
 
Join Date: Dec 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Peter, much appreciated.





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





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