to create a logic of specific pattern

Posted by Ayshjain under C# on 8/27/2012 | Points: 10 | Views : 857 | Status : [Member] | Replies : 5
How to create a logic to make pattern of "ABC001" with increasing numbers to ABC001,ABC002.....
to insert into database to generate id




Responses

Posted by: Gopesh9 on: 8/27/2012 [Member] Starter | Points: 25

Up
0
Down
Keep two string str1 = "ABC" and str2 = "001" and then concat them, at first you have to convert the 2nd string in the integer and then increment it after that concat it with the first...

G. S.
.Net Developer

Ayshjain, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ayshjain on: 8/27/2012 [Member] Starter | Points: 25

Up
0
Down
string firstPart = lastAdfId.Substring(0, 3);
string lastPart = lastAdfId.Substring(3);
int number = Int32.Parse(lastPart);
number++;
return firstPart + number.ToString();

it is generating numbers like ABC1,ABC2..

Ayshjain, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gopesh9 on: 8/27/2012 [Member] Starter | Points: 25

Up
0
Down
When you will convert that in ToString, just check the length, if the length is 1 then append two zeroes in front of that..

Like
string str = number.Tostring();

int r = str.Length;
if(r==1)
{
str = "00" + number;
}
if(r==2)
{
str = "0" + number;
}

return firstpart + str;


G. S.
.Net Developer

Ayshjain, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ayshjain on: 8/27/2012 [Member] Starter | Points: 25

Up
0
Down
thanks....

Ayshjain, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gopesh9 on: 8/27/2012 [Member] Starter | Points: 25

Up
0
Down
Mark as resolved post, if your problem is solved.

G. S.
.Net Developer

Ayshjain, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response