[Solved] Insert A Character After 7 Characters (C#) [closed]


Short Answer

You can use String.Insert.

String.Insert

public string Insert(
    int startIndex,
    string value
)

startIndex
Type: System.Int32
The zero-based index position of the insertion.
value
Type: System.String
The string to insert.

Explanation

This Method inserts a string into another string at the specified index position. The first parameter, startIndex is the zero-based index position of the insertion, and you want to insert it at the index position of 3, and you want the first parameter to be 3. The second parameter is the string to insert, and you want to insert -, so set the second parameter to a -.

Code:

string idnumber = "0002232";
string displayednumber = idnumber.Insert(3, "-");

Result:

displayednumber = "000-2232"

Try it online

http://rextester.com/LFDK8166

3

solved Insert A Character After 7 Characters (C#) [closed]