?
Solved

Replace space character with underscore character in string

Posted on 2006-06-21
5
Medium Priority
?
3,122 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 800 total points
ID: 16956168
Replace is a function:
  MyString = MyString.Replace(" ", "_")

Bob
0
 
LVL 11

Assisted Solution

by:anyoneis
anyoneis earned 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month12 days, 18 hours left to enroll

777 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