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

String length using " "c,10

P: n/a
Can anyone tell me what the "c" means in a statement like this:

strTest = New String(" "c,10)

I know the 10 in above example stands for the maxlength of characters
in the string. Is it posible to skip this maxlength?

I'm trying to open a textfile an put it into a string, and therefor I
just want to read the whole textfile til EOF.

I'm a bit new programming in Visual Basic.NET so I hope you remember
that in your answers.

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

P: n/a

"CeyloR" <w.*****@gmail.com> wrote in message
news:11********************@g43g2000cwa.googlegrou ps.com...
Can anyone tell me what the "c" means in a statement like this:

strTest = New String(" "c,10)

I know the 10 in above example stands for the maxlength of characters
in the string. Is it posible to skip this maxlength?

I'm trying to open a textfile an put it into a string, and therefor I
just want to read the whole textfile til EOF.

I'm a bit new programming in Visual Basic.NET so I hope you remember
that in your answers.


The "c" following the " means the previous string is converted to a
character :)

HTH,
Mythran

Nov 21 '05 #2

P: n/a
the c stands for a character contstant (it will in this case enforce the
usage of only one character , in the overloaded method )

strTest = New String(" "c,10) will result in a string containing 10 blank
spaces " "
as
strTest = New String("A"c,10) will result in a string containing
"AAAAAAAAAA"

to read a textfile line by line untill the end
dim sread as New StreamReader(PathToFile)

dim strFileContent as string

Do Until sread.Peek = -1

strFileContent = string.concat(strFileContent ,sread.ReadLine)

Loop

i hope this helped

regards

Michel Posseth [MCP]
"CeyloR" <w.*****@gmail.com> wrote in message
news:11********************@g43g2000cwa.googlegrou ps.com...
Can anyone tell me what the "c" means in a statement like this:

strTest = New String(" "c,10)

I know the 10 in above example stands for the maxlength of characters
in the string. Is it posible to skip this maxlength?

I'm trying to open a textfile an put it into a string, and therefor I
just want to read the whole textfile til EOF.

I'm a bit new programming in Visual Basic.NET so I hope you remember
that in your answers.

Nov 21 '05 #3

P: n/a

Mythran wrote:
The "c" following the " means the previous string is converted to a
character :)


Not exactly. It means that it is a character constant as opposed to a
string constant. No conversion takes place.
strTest = New String(" "c,10)


The same thing can be achieved with this line:

Dim strTest As String = " " '<--Note there are 10 spaces

Nov 21 '05 #4

P: n/a
"CeyloR" <w.*****@gmail.com> schrieb
Can anyone tell me what the "c" means in a statement like this:

strTest = New String(" "c,10)

I know the 10 in above example stands for the maxlength of
characters in the string. Is it posible to skip this maxlength?

I'm trying to open a textfile an put it into a string, and therefor
I just want to read the whole textfile til EOF.

I'm a bit new programming in Visual Basic.NET so I hope you remember
that in your answers.


http://msdn.microsoft.com/library/en...BSpec2_4_5.asp
Armin
Nov 21 '05 #5

P: n/a
"Chris Dunaway" <du******@gmail.com> schrieb

Mythran wrote:
The "c" following the " means the previous string is converted to
a character :)


Not exactly. It means that it is a character constant as opposed to
a string constant. No conversion takes place.
strTest = New String(" "c,10)


The same thing can be achieved with this line:

Dim strTest As String = " " '<--Note there are 10 spaces


It's a literal, not a constant. You need the 'Const' keyword to declare a
constant.
Armin

Nov 21 '05 #6

P: n/a
Thanks all for the fast and clear replies.

@Michel Posseth:

The method to read a whole textfile works great!

Nov 21 '05 #7

P: n/a
CeyloR,
In addition to the other comments:

" "c is a character literal.

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

While " " is a string literal.

http://msdn.microsoft.com/library/de...BSpec2_4_4.asp
A "constant" is "a constant value that is a member of a type".

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

Although it *is* common practice to refer to literals as constants.
Constants don't have to be literals, they can be expressions...

Hope this helps
Jay
"CeyloR" <w.*****@gmail.com> wrote in message
news:11********************@g43g2000cwa.googlegrou ps.com...
| Can anyone tell me what the "c" means in a statement like this:
|
| strTest = New String(" "c,10)
|
| I know the 10 in above example stands for the maxlength of characters
| in the string. Is it posible to skip this maxlength?
|
| I'm trying to open a textfile an put it into a string, and therefor I
| just want to read the whole textfile til EOF.
|
| I'm a bit new programming in Visual Basic.NET so I hope you remember
| that in your answers.
|
Nov 21 '05 #8

P: n/a
Hmm... Why not use the StreamReader's ReadToEnd function?
Nov 21 '05 #9

P: n/a
Yep you are right

didn`t thought of that because i normally need to parse my files line by
line ( was a copy paste action )
but indeed if you do not need to parse anything and just need to read it in
one operation to a string the readtoend option is better

regards

Michel Posseth
"Dragon" <no@spam.please> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
Hmm... Why not use the StreamReader's ReadToEnd function?

Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.