Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Difference between Strings and characters
Message
From
05/03/2005 07:44:02
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00992982
Message ID:
00992990
Views:
22
>Hi.
>I've been doing a fair bit of work manipulating strings recently and would appreciate some clarification:
>
>1. Whats the difference between string and char type.
> Is a string of length 1 the same as char ??
>
>2. I've used a few differnet ways to convert data and wonder which is the
>most appropriate to use
>
>
>e.g.
>MyNewChar = (char)MyInteger;
>MyNewChar = Char.Parse(MyString);
>
>Can any data type be parsed and are there any speed implications
>(I know from VFP that there are efficient and not so efficient methods of handling strings)
>
>Regards,
>
>Gerard

Gerard,
A string is a reference type but a char is a valuetype. A string of length 1 is not the same as char (BTW char is not 0-255 but all unicode range 0-65535, sounds like ushort but not implicitly catable and not all operations of ushort permitted). IOW a char is a 16bits unit and a string is a sequence of 16bits units (chars) (In C# strings are unicode).
A string could be converted to a char array:

char[] myChars = "My String".ToCharArray(); // or part of it with overload start,length

There is no implicit conversion from other types to char (including byte,sbyte,ushort which fall in range). You should use literals and casting:

MyNewChar c = '\x000D' // chr(13) in VFP
MyNewChar c = (char)13

MyNewChar c = (char)MyInteger casting would cause a compiler warning or error I think (overflow) and you'd need checked/unchecked.

Any datatype can be parsed? Parsing is a debatable term. In the sense I think you meant it yes. Speed-good question with no exact answer.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform