# 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:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [January 3, 2026, 8:34am UTC](https://forum.xojo.com/t/fill-up-a-string-with-given-char/87352/21 "2026-01-03T08:34:16Z")

</div>

> [@Farai\_Aschwanden](#):
>
> Fill up “1111” on the right by “ **0** ” to the max length of 8 → Output: “1111 **0000** ”

> I only want to fill up to 8 bits (1 byte).

Hang on a minute.

What you are actually wanting to do is create a string which is a binary representation of a number held in a byte?

This number is 120 in decimal…

to get the full binary string, you can just use

```auto
dim s as string
s = bin(120)

//result = “111100”

```

If you are staring with a binary value which has arrived as a nibble…

```auto
dim s as string
dim v as byte
v = &b1111
//we have a nibble and want to push it into the higher nibble
v = v * 8

s = bin(v)

```

---

<div class="post-metadata">

**Author:** ![Farai\_Aschwanden](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/e79b87/32.png) [@Farai\_Aschwanden](https://forum.xojo.com/u/Farai_Aschwanden)\
**Post date:** [January 3, 2026, 9:57am UTC](https://forum.xojo.com/t/fill-up-a-string-with-given-char/87352/22 "2026-01-03T09:57:49Z")

</div>

The “1111” was just a random example. I got different binary strings returned, with different lengths, from 0 to already wanted length of 8. In the end I want to ensure it has a length of 8 bits (1 byte), no matter what it was before.

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [January 3, 2026, 10:21am UTC](https://forum.xojo.com/t/fill-up-a-string-with-given-char/87352/23 "2026-01-03T10:21:26Z")

</div>

> [@Farai\_Aschwanden](#):
>
> I got different binary strings returned, with different lengths, from 0 to already wanted length of 8

If you get sent 1111 , that’s 15 decimal

If you pad on the right to end up with 1111000, you make it into 120 decimal

So padding on the right with zeroes sounds a little dangerous - are you _sure_ you end up with the right values?

---

<div class="post-metadata">

**Author:** ![Farai\_Aschwanden](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/e79b87/32.png) [@Farai\_Aschwanden](https://forum.xojo.com/u/Farai_Aschwanden)\
**Post date:** [January 3, 2026, 10:39am UTC](https://forum.xojo.com/t/fill-up-a-string-with-given-char/87352/24 "2026-01-03T10:39:54Z")

</div>

Thanks, I’m aware of that. Sorry to all for that confusion, bad typo!

I need to fill up on the left side in this case: “1111” → “ **0000** 1111”. I was initially asking for LPAD, RPAD. So if there would be an **L** PAD, there would also be an **R** PAD function. In my case I would do a LPADding while others might need RPAD for their purposes.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [January 3, 2026, 7:21pm UTC](https://forum.xojo.com/t/fill-up-a-string-with-given-char/87352/25 "2026-01-03T19:21:03Z")

</div>

> [@Farai\_Aschwanden](#):
>
> I need to fill up on the left side in this case: “1111” → “ **0000** 1111”. I was initially asking for LPAD,

Use my previous Replicate() function + this LeftPad() function:

```auto
Public Function LeftPad(str As String, size As Integer, padChar As String = " ") As String

  If padChar.Length <> 1 Then
    Raise New RuntimeException("The pad char must have a length of 1")
  End
  Return Replicate(padChar, size - str.Length) + str
  
End Function

```

 ![image](https://forum.xojo.com/uploads/default/original/3X/8/e/8e804db1d1ed81d0ab3679154dfa9ef229fae4bc.png)

---

<div class="post-metadata">

**Author:** ![Farai\_Aschwanden](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/e79b87/32.png) [@Farai\_Aschwanden](https://forum.xojo.com/u/Farai_Aschwanden)\
**Post date:** [January 4, 2026, 7:48pm UTC](https://forum.xojo.com/t/fill-up-a-string-with-given-char/87352/26 "2026-01-04T19:48:14Z")

</div>

Excellent, thank you!

[Previous page](https://forum.xojo.com/t/fill-up-a-string-with-given-char/87352.md?page=1)
