By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,191 Members | 1,411 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,191 IT Pros & Developers. It's quick & easy.

Fixed Size String

P: n/a
cvh
Hello,

In delphi I could do this :

Var Str: String[2] (String of size 2char)

How would I do this with VB.NET in CF?

Thank you,

Christophe
Nov 21 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
"cvh" <Ch***@nomail.com> wrote in message
news:eI**************@TK2MSFTNGP09.phx.gbl...
In delphi I could do this :
Var Str: String[2] (String of size 2char)

How would I do this with VB.NET in CF?


Why would you need to?

Support for fixed length strings is available, but requires use of
the VB "Compatibility" Library, which may or may not be
supported in future releases of the Framework.

However, there are lots of other ways of handling this kind of thing.
What exactly do you need to /do/ with this fixed length string?

Regards,
Phill W.
Nov 21 '05 #2

P: n/a
"cvh" <Ch***@nomail.com> schrieb:
Var Str: String[2] (String of size 2char)

How would I do this with VB.NET in CF?


Simply assign a string with 2 characters length to a string variable :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

P: n/a
Phill,

for this I am as well real curious for.

Why would you need to?

Cor
Nov 21 '05 #4

P: n/a
cvh
So making a string fixed size won't save RAM?
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
"cvh" <Ch***@nomail.com> schrieb:
Var Str: String[2] (String of size 2char)

How would I do this with VB.NET in CF?


Simply assign a string with 2 characters length to a string variable :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

P: n/a
cvh
A string is in memory as long as it is used in dotNet plus its reference of
course.

When it is changed than there will be made a complete new one and the old
one will be destroyed.

I hope this gives some ideas

Cor
Nov 21 '05 #6

P: n/a
"cvh" <Ch***@nomail.com> schrieb:
So making a string fixed size won't save RAM?


Why should it save memory? Fixed size strings make sense in some interop
scenarios, but in general it's better to stick with normal strings.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7

P: n/a
Bob
Not that it's likely that you need it, but to technically achieve a fixed length string without
resorting to interop, you can use the old-school approach:

Dim SomeFixedLengthString As Char(2)
SomeFixedLengthString(0) = "h"c
SomeFixedLengthString(1) = "i"c

Or...

Dim SomeFixedLengthString As Char() = {"h"c, "i"c}

Just like in LISP. Man, that brings back memories. I hated using EMACS as a debugger...

Bob

"cvh" <Ch***@nomail.com> wrote in message news:eI**************@TK2MSFTNGP09.phx.gbl...
Hello,

In delphi I could do this :

Var Str: String[2] (String of size 2char)

How would I do this with VB.NET in CF?

Thank you,

Christophe

Nov 21 '05 #8

P: n/a
"Bob" <no***@nowhere.com> schrieb:
Not that it's likely that you need it, but to technically achieve a fixed
length string without
resorting to interop, you can use the old-school approach:

Dim SomeFixedLengthString As Char(2)
SomeFixedLengthString(0) = "h"c
SomeFixedLengthString(1) = "i"c

Or...

Dim SomeFixedLengthString As Char() = {"h"c, "i"c}


Still, this doesn't limit 'SomeFixedLengthString' to the type "String of
length 2". For example, if a class exposes a 'PrimaryLanguageCode' property
that should only accept strings consisting of two characters, you cannot
enforce that at compiletime. What you can do is throwing an exception in
the property's 'Set' part if a client tries to assign a shorter or longer
string.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9

P: n/a
Herfried,

You can fix the length of a string (as long that you do not paste it in) in
a textbox.

What I hope explain direct the rest.

(I know that you know that as well)

Cor
Nov 21 '05 #10

P: n/a
I think you are just like me. I was facing a problem when I was writing a
conversion program to work with COBOL85. You can pad the string after you
assign the value:

http://msdn.microsoft.com/library/de...RightTopic.asp

chanmm

"cvh" <Ch***@nomail.com> wrote in message
news:eI**************@TK2MSFTNGP09.phx.gbl...
Hello,

In delphi I could do this :

Var Str: String[2] (String of size 2char)

How would I do this with VB.NET in CF?

Thank you,

Christophe

Nov 21 '05 #11

P: n/a
cvh
Thanks 4 the replies guys.
"cvh" <Ch***@nomail.com> wrote in message
news:eI**************@TK2MSFTNGP09.phx.gbl...
Hello,

In delphi I could do this :

Var Str: String[2] (String of size 2char)

How would I do this with VB.NET in CF?

Thank you,

Christophe

Nov 21 '05 #12

P: n/a
guy
a fixed length string ***might*** save memory, normally the word length you
are working with. so on current 32bit intel/amd cpus you will save 4 bytes
per string.
This mattered 25 years ago with 8 bit cpus and 64Kb memory, but now a few
bytes saved is worth nothing comapred to the development gain of not having
to worry about them

hth

guy

"cvh" wrote:
So making a string fixed size won't save RAM?
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
"cvh" <Ch***@nomail.com> schrieb:
Var Str: String[2] (String of size 2char)

How would I do this with VB.NET in CF?


Simply assign a string with 2 characters length to a string variable :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #13

P: n/a
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
You can fix the length of a string (as long that you do not paste it in)
in a textbox.


That's true, but I don't see the relation to the OP's question ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.