Hello,

I am trying to use this code:

PictureBox1.ImageLocation = "http://avatar.xboxlive.com/avatar/" & TextBox1.Text & "/avatar-body.png".Replace(" ", "%20%");

The error I get is:

Error	2	Operator '&' cannot be applied to operands of type 'string' and 'string'	C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Lucky Se7en\Lucky Se7en\GamercardViewer.cs	27	37	Lucky Se7en

Dani AI

Generated

This is a C# issue, not a VB one — was right that C# uses + for string concatenation. The compile error comes from using the VB-style & in a .cs file, and the .Replace call in the original expression only applies to the string it’s attached to (because the member access operator has higher precedence than +/concatenation). That means your replace wasn’t running on the whole URL anyway.

Quick fixes you can apply:

// apply Replace to the whole concatenated URL
pictureBox1.ImageLocation = (baseUrl + TextBox1.Text + suffix).Replace(" ", "%20");

A more robust and correct approach is to URL-encode the user-provided segment so other unsafe characters are handled too:

string baseUrl = baseAvatarHost;     // your avatar host/base
string segment = TextBox1.Text;
string safeSegment = Uri.EscapeDataString(segment);
pictureBox1.ImageLocation = baseUrl + safeSegment + pathSuffix;

Notes and troubleshooting tips:

  • Prefer Uri.EscapeDataString for path segments; HttpUtility.UrlEncode will turn spaces into + (form encoding), which is often not what you want in a URL path.
  • Watch for accidental typos in replacement strings (e.g., an extra %).
  • Trim or normalize trailing/leading slashes on baseUrl/pathSuffix to avoid //.
  • Log the final URL (Debug.WriteLine or watch) before assigning to ImageLocation to verify it’s correct and reachable.

These changes address both the language/operator mismatch and the encoding bug so the picture loader receives a valid URL.

Looks like you've already solved this but... erm... it's + not & for that type of usage :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.