Link to home
Start Free TrialLog in
Avatar of scm0sml
scm0sml

asked on

Swapping all instances of one character within a string with another character

Simple question but I'm struggling to find the answer anywhere.

I'm creating a new directory and want the name of the directory to be the date then time it was created.....taken from a DateTime object. e.g 27 April 2006 12:30:56

However the : in the time is an invalid character for a directory name so what I am doing at the mo is readin the time into a string and I want to swap the : for a valid character, say -.

How do I go about swapping these characters?

I'm open to suggesstions if any1 has a better method.


Cheers
SOLUTION
Avatar of SmithJW
SmithJW

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of scm0sml
scm0sml

ASKER

cheers both!
Hi scm0sml,
actually, you could do string s = DateTime.Now.ToString("dd MMMM yyyy hh-mm-ss");

Cheers!