Solved

Replace space character with underscore character in string

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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