How to read string value

I had one string value like A01-CMZX-001,A01-CMZX-002,A01-CMZX-003,A01-CMZX-004

for that i wrote the code like

public static str method(ItemCategory _itemCategory,Listvalue _listvalue,ItemId _itemId)
int _lineNo = 0;
str lineno;
str assetId;

str assetformate;
InventTable inventTable;
AssetTable assetTable;

select count(RecId) from inventTable where inventTable.ItemCatCode == _itemCategory;

lineno = int2str(_lineNo + 1);
assetformate = (_itemCategory+’-’+_listvalue +’-’+lineno);

Select inventTable where inventTable.ItemId == _itemId ;
// inventTable.AssetId = assetformate;

select forUpdate assetTable where assetTable.ItemId == _itemId;
assetTable.AssetItemId = assetformate;



return assetformate;

but some one is deleted the existing record then its generates last value of like
my need is it will go to generate next number A01-CMZX-005
so can any one help me