2

I am running my code in .NetCF and this line is showing error as

StringSplitOptions does not exists in the context.

Please help what I am doing wrong.

string[] values = headerData.Split(new string[] { "<#Tag(", ")>"},  StringSplitOptions.RemoveEmptyEntries);

Can I Fetch value1 value2 value3 from "<#Tag(value1)> <#Tag(value2> <#Tag(value3)>" and pass it to string[] without using StringSplitOptions

Parth Desai
  • 209
  • 2
  • 4
  • 19
  • Maybe related thread: [WIndows Mobile 6 SDK - string.Split and StringSplitOptions - can't find](http://stackoverflow.com/questions/31835127/) – Jeppe Stig Nielsen Jan 18 '16 at 12:04

3 Answers3

11

According to this reference, the .NET Compact Framework does not have StringSplitOptions.

Here is an alternative that uses Regex.Split:

string[] values =
    Regex.Split(headerData, "<#Tag\\(|\\)>")
    .Where(x => x != string.Empty)
    .ToArray();
Yacoub Massad
  • 27,509
  • 2
  • 36
  • 62
0

I'm pretty sure this overload is not supported in compact framework.
From MSDN:

Version Information
.NET Framework
Supported in: 3.5, 3.0, 2.0

as apposed to other split overloads such as String.Split Method (Char[]) where the documentation specifically mentions CF:

Version Information
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 3.5, 2.0, 1.0
XNA Framework
Supported in: 3.0, 2.0, 1.0

ATC
  • 907
  • 1
  • 9
  • 14
  • Newer versions of the documentation write the "Version Information" in a more verbose format, for example [`StringSplitOptions` Enumeration](https://msdn.microsoft.com/en-us/library/system.stringsplitoptions.aspx) currently has: `Version Information -- Universal Windows Platform Available since 4.5 .NET Framework Available since 2.0 Portable Class Library Supported in: portable .NET platforms Silverlight Available since 2.0 Windows Phone Silverlight Available since 7.0 Windows Phone Available since 8.1` – Jeppe Stig Nielsen Jan 18 '16 at 12:10
  • @JeppeStigNielsen: True, but this doesn't include .net compact framework. nor does portable .net platforms, note the [Target options part of the portable .net platforms](https://msdn.microsoft.com/en-us/library/gg597391.aspx#platforms) page. – ATC Jan 18 '16 at 12:19
  • While your answer is correct, the other answer is better since it's actually provides a solution to the problem and not just the cause. – Zohar Peled Jan 18 '16 at 13:16
  • Yes. It appears that in the .NET 3.5 days (2007/2008), they had ".NET Compact Framework" in which the enum type `StringSplitOptions` was **not** supported. This is what the asker uses. Then since .NET 4.0 time (2010), they (no longer talk about "Compact Framework" and) have "Portable Class Library" which **does** support `StringSplitOptions`. – Jeppe Stig Nielsen Jan 18 '16 at 13:19
0

Write the namespace "System" at the beginning of the Enum like this:

string[] values = headerData.Split(new string[] { "<#Tag(", ")>"}, System.StringSplitOptions.RemoveEmptyEntries);

It didn't work in my application when I only used StringSplitOptions for some reason.