Solved

Replace space character with underscore character in string

Posted on 2006-06-21
5
3,110 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now