HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to Classic ASPVariablesStringsConditions (If / Select Case)Loops (For / Do While)Form and Request
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
✍️ Text & Number
🔁 Condition & Loop
🧩 Functions & Forms
Classic ASP›Strings

Strings

String concatenation, length, and frequently used VBScript string functions.

Simple enough for a 5-year-old to understand

String concatenation

In VBScript, strings are concatenated using the ampersand (&) operator.

Example code
1
Dim name
2
name = "Alex"
3
Response.Write "Hello " & name
Hello Alex author.
Output / InputHello Alex author.
Output / Input
💡 Hint: Use the ampersand instead of the plus sign for concatenation; the plus sign causes confusion with numbers.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (1 left)

1.Which operator is used to concatenate two strings in VBScript?

About this topic

In VBScript, strings are written between double quotes, and to show a quote inside the string, the quote is written twice. The backslash is not an escape character; this makes file paths easier.

The correct operator for string concatenation is the ampersand sign. The plus operator also works in some cases, but when operands look like numbers, it attempts addition; therefore, the plus operator should never be used for string operations.

Positions in string functions start from one. Substring, search, and replacement functions are rich, but they all carry the traces of a language accustomed to fixed-length thinking and may throw an error when a null value is passed.

What you will learn

  • Concatenating text
  • For length and substring extraction
  • For search and replacement
  • For trimming whitespace
  • For escaping for output

Who is this for?

  • Those processing form data
  • Those generating HTML output
  • Those getting concatenation errors

When to use?

Every text from the user must be escaped for HTML before being printed to the page; this is the first defense against cross-site scripting attacks.

If you are concatenating many fragments inside a loop, a new string is created at each step; gathering fragments into an array and joining them at the end in a single operation provides a noticeable performance gain.

Common mistakes

Wrong

<%
Option Explicit
Dim ad, yas
ad = "Ayse"
yas = 30
Response.Write "Name: " + ad + " Age: " + yas
%>

The plus operator can throw a type mismatch error when concatenating a string and a number; its behavior depends on the subtype of the operands and is unpredictable. The ampersand operator should always be used for concatenating strings; it converts the operands to text and concatenates them.

Correct

<%
Option Explicit
Dim ad, yas
ad = "Ayse"
yas = 30
Response.Write "Name: " & ad & " Age: " & yas
%>

Wrong

<%
Option Explicit
Dim yorum
yorum = Request.Form("yorum")
Response.Write "<p>" & yorum & "</p>"
%>

Since user input is written directly to the page, someone putting a script tag inside it can run that script in every visitor's browser. Input must always be passed through an HTML escaping function; this is a serious vulnerability closed with a single line.

Correct

<%
Option Explicit
Dim yorum
yorum = Request.Form("yorum")
Response.Write "<p>" & Server.HTMLEncode(yorum) & "</p>"
%>

Wrong

<%
Option Explicit
Dim metin
metin = "merhaba"
Response.Write Mid(metin, 0, 3)
%>

In the substring function, positions start from one; zero is an invalid start and produces a runtime error. To get the first three characters, you need to start from position one. This is the first mistake made by those coming from zero-indexed languages.

Correct

<%
Option Explicit
Dim metin
metin = "merhaba"
Response.Write Mid(metin, 1, 3)
%>

Frequently asked questions

How are quotes written inside a string?

By writing the double quote twice. The backslash is not an escape character in VBScript, it is a plain character. Using single quotes in HTML attributes is also a common way to make writing easier.

How to add a line break?

The built-in line break constant is concatenated. In HTML output, a newline does not have a visual effect; a line break tag is needed to move to the next line in the browser. The two serve different purposes.

Do functions throw errors if null values are passed?

Some do. Undefined values coming from the database must be converted to an empty string before being passed to string functions; for this, a function that converts the value to a string or concatenating it with an empty string is used.

Summary

The ampersand operator is used for concatenation.

The plus operator is unreliable with strings.

Positions start from one.

Quotes are escaped by writing them twice.

User input must be escaped for HTML.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code