# Help concatenating letters and numbers

**URL:** <https://www.ruby-forum.com/t/help-concatenating-letters-and-numbers/153089>\
**Category:** Rails\
**Created:** [November 12, 2008, 12:22am UTC](https://www.ruby-forum.com/t/help-concatenating-letters-and-numbers/153089 "2008-11-12T00:22:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@The\_N](https://www.ruby-forum.com/u/The_N)\
**Post date:** [November 12, 2008, 12:22am UTC](https://www.ruby-forum.com/t/help-concatenating-letters-and-numbers/153089/1 "2008-11-12T00:22:45Z")

</div>

Hello…

I need to do the following in rails:

I have a string with the following composition: AAA-BBB-2008-000001

The first to groups are strings, named @string1 and @string2. The  
third is the year, (reflected using Time.now.strftime("%Y")) and the  
last part is an integer, @integer1.

I’m using a PostgreSQL 8 database and I need to put that composition  
on a string.I have no problem with the string variables and the year.  
The catch here is the integer, it increases everytime I do a new  
registry and, when a new year comes, it resets to 1. More over, I need  
the integer to be 6-digit.I don’t know how to do that, but I know the  
logic of th increments:

When the integer is 10, I need it to be 000010; when it’s 100, 000100;  
1000 =\> 001000 and so on.

And let’s suppose one of our string changes, for example. It also must  
resets the integer to 1.

As you can see, it’s a unique composition.

As the id from the database keeps increasing, that number won’t work  
on me. I need to set it apart, without using that number. And that  
count must be kept, whenever I log in to my app.

Is it hard to do this stuff?

Greetings…

The N.

---

<div class="post-metadata">

**Author:** ![The\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@The\_N](https://www.ruby-forum.com/u/The_N)\
**Post date:** [November 12, 2008, 3:02pm UTC](https://www.ruby-forum.com/t/help-concatenating-letters-and-numbers/153089/2 "2008-11-12T15:02:19Z")

</div>

you can use sprintf formatting for the integer:

@integer1 = 10  
int\_formatted = “%06d” % @integer1 # returns “000010”

I don’t understand the other requirements enough to help further
