String length using " "c,10

  • Thread starter Thread starter CeyloR
  • Start date Start date
C

CeyloR

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.
 
CeyloR said:
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
 
CeyloR said:
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-us/vbls7/html/vblrfVBSpec2_4_5.asp


Armin
 
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]
 
Mythran said:
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.

The same thing can be achieved with this line:

Dim strTest As String = " " '<--Note there are 10 spaces
 
Chris Dunaway said:
Not exactly. It means that it is a character constant as opposed to
a string constant. No conversion takes place.


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
 
Thanks all for the fast and clear replies.

@Michel Posseth:

The method to read a whole textfile works great!
 
CeyloR,
In addition to the other comments:

" "c is a character literal.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbls7/html/vblrfVBSpec2_4_5.asp

While " " is a string literal.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbls7/html/vblrfVBSpec2_4_4.asp


A "constant" is "a constant value that is a member of a type".

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbls7/html/vblrfVBSpec7_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


| 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.
|
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top