Click here to Skip to main content
15,892,809 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# Windows Service Pin
AspDotNetDev9-Jun-11 8:28
protectorAspDotNetDev9-Jun-11 8:28 
AnswerRe: C# Windows Service Pin
Luc Pattyn9-Jun-11 8:53
sitebuilderLuc Pattyn9-Jun-11 8:53 
QuestionCallbackOnCollectedDelegate exception when using DDE to get URLs from Navigators Pin
moums8-Jun-11 13:54
moums8-Jun-11 13:54 
Questionstring formate Pin
jashimu8-Jun-11 8:20
jashimu8-Jun-11 8:20 
AnswerRe: string formate Pin
Ennis Ray Lynch, Jr.8-Jun-11 8:29
Ennis Ray Lynch, Jr.8-Jun-11 8:29 
AnswerRe: string formate Pin
mabrahao8-Jun-11 9:07
mabrahao8-Jun-11 9:07 
AnswerRe: string formate Pin
AspDotNetDev8-Jun-11 9:16
protectorAspDotNetDev8-Jun-11 9:16 
AnswerRe: string formate Pin
AspDotNetDev8-Jun-11 9:15
protectorAspDotNetDev8-Jun-11 9:15 
Try this:
C#
string p = TextBox.Text.Trim();
p = string.Format("{0} {1} {2}", p.Substring(0, 2), p.Substring(2, 3), p.Substring(5, 3));
// If you are using Windows Forms, this will show the output. You will do it differently if you are using ASP.NET.
MessageBox.Show(p);

Here is what was wrong with your code:
  • Your sample output contains spaces, but your format strong contains commas.
  • string.Format returns the modified string, yet you were not assigning the return value to anything.
  • string.Substring has 2 parameters. The second prameter is the string length, not a second index. So where you used 4 and 7, you should have used 3.


GeneralRe: string formate Pin
jashimu8-Jun-11 11:04
jashimu8-Jun-11 11:04 
AnswerRe: string formate Pin
Pete O'Hanlon8-Jun-11 10:55
mvePete O'Hanlon8-Jun-11 10:55 
GeneralRe: string formate Pin
AspDotNetDev8-Jun-11 11:38
protectorAspDotNetDev8-Jun-11 11:38 
AnswerRe: string formate PinPopular
Luc Pattyn8-Jun-11 12:32
sitebuilderLuc Pattyn8-Jun-11 12:32 
GeneralRe: string formate Pin
AmbiguousName8-Jun-11 21:46
AmbiguousName8-Jun-11 21:46 
GeneralRe: string formate Pin
Lutosław11-Jun-11 12:13
Lutosław11-Jun-11 12:13 
AnswerRe: string formate Pin
Luc Pattyn11-Jun-11 12:17
sitebuilderLuc Pattyn11-Jun-11 12:17 
GeneralRe: string formate Pin
Lutosław11-Jun-11 12:45
Lutosław11-Jun-11 12:45 
AnswerRe: string formate Pin
Luc Pattyn11-Jun-11 12:51
sitebuilderLuc Pattyn11-Jun-11 12:51 
Questioninstantiating a generic object [modified] Pin
mabrahao8-Jun-11 5:53
mabrahao8-Jun-11 5:53 
AnswerRe: instantiating a generic object Pin
Ennis Ray Lynch, Jr.8-Jun-11 6:11
Ennis Ray Lynch, Jr.8-Jun-11 6:11 
GeneralRe: instantiating a generic object Pin
mabrahao8-Jun-11 7:43
mabrahao8-Jun-11 7:43 
GeneralRe: instantiating a generic object Pin
dasblinkenlight8-Jun-11 8:15
dasblinkenlight8-Jun-11 8:15 
GeneralRe: instantiating a generic object Pin
mabrahao8-Jun-11 8:36
mabrahao8-Jun-11 8:36 
GeneralRe: instantiating a generic object Pin
dasblinkenlight8-Jun-11 8:42
dasblinkenlight8-Jun-11 8:42 
GeneralFull example PinPopular
Ennis Ray Lynch, Jr.8-Jun-11 8:28
Ennis Ray Lynch, Jr.8-Jun-11 8:28 
GeneralRe: Full example Pin
mabrahao8-Jun-11 8:42
mabrahao8-Jun-11 8:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.