Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format string the way I want it to look

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
Hi,
I have a string that looks like this 43100008, I want it to look like this 4.31.00.008.

I have tried numerous String.Format options, but none seem to just format the string correctly.

Any Idea's?

Thanks,
RalphTrent
 
At this risk of simplifying your problem or not understanding it correctly, but are you just looking for something like this:
Code:
string thisString = "43100008";
string newString = thisString.Substring(1,1) + "." + thisString.Substring(2,2) + "." + thisString.Substring(4,2) + "." + thisString.Substring(6,3);
It shouldn't be difficult to automate something from here provided you have a standard that you're trying to adhere to.

------------------------------------------------------------------------------------------------------------------------
Reason and free inquiry are the only effectual agents against error; they are the natural enemies of error and of error only.

Thomas Jefferson

 
I was able to use the substring method, but I thought there would be an easier way to use the String.Format method. I do not see why MSFT will not allow for this.
 
This may be helpful... Or not...


------------------------------------------------------------------------------------------------------------------------
Reason and free inquiry are the only effectual agents against error; they are the natural enemies of error and of error only.

Thomas Jefferson

 
Alternatively...

Code:
string s = "43100008";
s = s.Insert(1,".").Insert(4,".").Insert(7,".").Insert(11,".");

Ryan
 
Ryan,
Thanks for the idea, I will have to give that a shot.

RalphTrent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top