Solved

Replace space character with underscore character in string

Posted on 2006-06-21
5
3,114 Views
Last Modified: 2011-10-03
Just need to replace space character with underscore character in string.

I have tried:

MyString.Replace(" ", "_")

And that doesn't seem to have any effect, but doesn't throw any exceptions or errors either.
0
Comment
Question by:mynameiskristopher
5 Comments
 
LVL 12

Expert Comment

by:fruhj
ID: 16955859
I don't have docs in front of me, and your example looks right,

Are you sure the order is correct (ie its not "_", " ")  is it?

Lastly I once had something like this, turned out the character was not actually a space (I think space is ascii 32, this one was like 169 or something!)

So if worst comes to worst, loop through each char in your stirng and print the ascii value to confirm you have a space.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 200 total points
ID: 16956168
Replace is a function:
  MyString = MyString.Replace(" ", "_")

Bob
0
 
LVL 11

Assisted Solution

by:anyoneis
anyoneis earned 100 total points
ID: 16957601
More to the point, Strings are imutable. So a function will never modify a string, it will usually return a modified copy of the string which you need to capture and/or use.

David
0
 
LVL 4

Expert Comment

by:jtaylor8181
ID: 16960002
just try this

mystring = Replace(ChrW(32), "_", mystring)
or
mystring = Replace(" ", "_", mystring)

jtaylor
0
 

Author Comment

by:mynameiskristopher
ID: 16960015
TheLearnedOne, Thanks for your straightforward example, and anyoneis thanks for the explanation. Just wasn't thinking.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
I need help converting a bitmap to an image in VB.Net 1 44
VB.NET 1 28
How do sunrise and sunset times change with altitude 14 38
VB.Net - String Manipulation Scenario 2 25
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question