---
title: "padding(toLength:withPad:startingAt:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/padding(tolength:withpad:startingat:)"
---

# padding(toLength:withPad:startingAt:)

Returns a new string formed from the receiver by either removing characters from the end, or by appending as many occurrences as necessary of a given pad string.

## Declaration

```swift
func padding(toLength newLength: Int, withPad padString: String, startingAt padIndex: Int) -> String
```

## Parameters

- `newLength`: The new length for the receiver.
- `padString`: The string with which to extend the receiver.
- `padIndex`: The index in padString from which to start padding.

## Return Value

Return Value A new string formed from the receiver by either removing characters from the end, or by appending as many occurrences of padString as necessary.

## Discussion

Discussion Here are some examples of usage: [@"abc" stringByPaddingToLength: 9 withString: @"." startingAtIndex:0];     // Results in "abc......"   [@"abc" stringByPaddingToLength: 2 withString: @"." startingAtIndex:0];     // Results in "ab"   [@"abc" stringByPaddingToLength: 9 withString: @". " startingAtIndex:1];     // Results in "abc . . ."     // Notice that the first character in the padding is " "

## See Also

### Combining Strings

- [appendingFormat(_:_:)](foundation/nsstring/appendingformat(_:_:).md)
- [appending(_:)](foundation/nsstring/appending(_:).md)
