1

Numeric

  string a = String.Format("{0:#/#}",12)

output:1/2

But How to Convert it for string Suppose

  String b=String.Format("{0:###-#}","test")

Output : test

Expected Output: tes-t

1
  • 4
    # is a digit placeholder format. It doesn't denote 'characters'. Commented Jul 12, 2012 at 18:13

2 Answers 2

6

You can't format a string through string.Format for the reason that it is already a string.

If you want to manipulate the string, use the methods defined on the string class.

Sign up to request clarification or add additional context in comments.

Comments

1

I think you can split the string to its characters and then use format

string testString = "test";
string formattedString = string.Format("{0}{1}{2}-{3}", testString.Select(c => c.ToString()).ToArray());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.