# Fill up a string with given char

**URL:** <https://forum.xojo.com/t/fill-up-a-string-with-given-char/87352>\
**Category:** General\
**Created:** [December 31, 2025, 10:59am UTC](https://forum.xojo.com/t/fill-up-a-string-with-given-char/87352 "2025-12-31T10:59:02Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [December 31, 2025, 12:49pm UTC](https://forum.xojo.com/t/fill-up-a-string-with-given-char/87352/2 "2025-12-31T12:49:39Z")

</div>

Here’s an extension function that you can put in a module for left or right padding:

```auto
Public Function Pad(extends input as String, padCharacter as String = "0", left as Boolean = True, toLength as Integer = 16) As String
  '// Example usage
  ' Var s as String = "1011"
  ' s = s.Pad("0", False, 8)
  '   
  ' Result: 10110000
  var data() as String = input.ToArray( "" )
  var originalLength as Integer = data.LastIndex
  
  for index as Integer = originalLength to toLength - 2
    if left then
      data.AddAt( 0, padCharacter )
    else
      data.Add( padCharacter )
    end if
  next
  
  Return String.FromArray( data, "" )
End Function

```

---

_[View the full topic](https://forum.xojo.com/t/fill-up-a-string-with-given-char/87352)._
