473,395 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Strings, a couple of questions like difference between += and &=

What's the difference between += and &= with reference to strings?

Also, what are string literals? Thanks.

And what are fixed lenth strings? and how do you declare them? Thanks

Oct 2 '06 #1
3 1006
James,

It is better not to use in visual basic the + with strings. There can be
problems with that when you have option strict of.

string b as string = 10
b += "2"
will result in 12 with option strict of.

string b as string = 10
b &= "2"
will result in 102, mostly the wanted result in this kind of use.

I hope this gives an idea,

Cor

"James" <ja**********@gmail.comschreef in bericht
news:11**********************@m7g2000cwm.googlegro ups.com...
What's the difference between += and &= with reference to strings?

Also, what are string literals? Thanks.

And what are fixed lenth strings? and how do you declare them? Thanks

Oct 2 '06 #2
"Cor Ligthert [MVP]" <no************@planet.nlschrieb:
It is better not to use in visual basic the + with strings. There can be
problems with that when you have option strict of.
That's true. In addition you need 'CStr' or 'ToString' calls which are not
always necessary when using '&' because it performs conversion to string
automatically.
string b as string = 10
b += "2"
will result in 12 with option strict of.
No, it will result in "102".

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

Oct 2 '06 #3
James wrote:
What's the difference between += and &= with reference to strings?
With Option Strict On - which I would /strongly/ recommend -
None at all.

With Option Strict Off, the + sign can be "misinterpreted" by the
compiler depending on the Type of data values being used.

Dim s As String = "3"
Dim i As Integer = 1

s += i

Should the result be "31" ("3" + CStr(1)) or "4" (CStr(CInt("3") + 1)))?

Stick to "&" - there's no confusion that way.
And turn Option Strict On so you can't trip yourself up.
Also, what are string literals?
"This is a String Literal" :-)

String Literal ::= A string value that appears /in your code/ with
leading and trailing double-quotes.
And what are fixed lenth strings? and how do you declare them? Thanks
These are Strings whose value is /always/ a pre-defined number of
characters long, no matter how much you try to put into it.
For example, if you have a five-character fixed-length String, fs:

fs = "A"
?"(" & fs & ")"
(A )

They're useful if you're dealing with flat (say, COBOL-generated) files
where each data field is delimited /only/ by its total length.

Avoid using them if at all possible. Instead, write code that reads and
writes the fixed-length data, but store the values internally in
ordinary, variable-length Strings.

HTH,
Phill W.
Oct 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Ravi | last post by:
Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT"...
13
by: Randy Webb | last post by:
Just for my own curiosity, what ever happend to the Java Applet that was referenced in the FAQ along with the HTTPRequestObject? http://jibbering.com/faq/#FAQ4_34 And in...
5
by: Colin Savage | last post by:
Please could somebody explain what an "atomized string" is? I have been doing loops in the msdn around XmlNameTable and NameTable but neither explain what an atomized string is. The example for one...
23
by: Il Prof | last post by:
Hi! I'm new in C language (but not in structured programming) and i have some questions about strings: 1) What of this two string access methods is faster? - Direct access of the elemtns of...
20
by: Trevor | last post by:
I have a couple of questions regarding C# strings. 1) Sometimes I see a string in someone else's code like: string foo = @"bar"; What does the '@' do for you? 2) Is there a performance...
6
by: Broeisi | last post by:
Hello, I wrote the tiny progam below just to understand arrays and strings better. I have 2 questions about arrays and strings in C. 1. Why is it that when you want to assign a string to an...
0
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
23
by: arnuld | last post by:
i was doing exercise 4.3.1 - 4.29 of "C++ Primer 4/e" where authors, with "run-time shown", claim that C++ Library strings are faster than C-style character strings. i wrote the same programme in...
2
by: Marco Trapanese | last post by:
Hello, I have to define a structure for a plain-text input file. It should have some general text fields and a long table of values. These values are grouped by rows and can be integers, floats,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.