[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3128
  • Last Modified:

Replace space character with underscore character in string

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
mynameiskristopher
Asked:
mynameiskristopher
2 Solutions
 
fruhjCommented:
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
 
Bob LearnedCommented:
Replace is a function:
  MyString = MyString.Replace(" ", "_")

Bob
0
 
anyoneisCommented:
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
 
jtaylor8181Commented:
just try this

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

jtaylor
0
 
mynameiskristopherAuthor Commented:
TheLearnedOne, Thanks for your straightforward example, and anyoneis thanks for the explanation. Just wasn't thinking.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now