Henry Olive 4 Posted Thursday at 09:13 AM Good Day, MyCode in Database = VARCHAR(20) MyCode could be (120 or 250) like 3 digit Integer, or (200.001 or 600.010) there is a dot between numbers, or (500.005.0010 or 100.010.1500) there are 2 dots between numbers I need to Increase MyCode by 1 that is if MyCode = 100 then requested result = 101 if MyCode = 300.001 then requested result = 300.002 if MyCode = 600.005.0010 then requested result = 600.005.0011 How can i do that ? Thank You Share this post Link to post
Sherlock 466 Posted Thursday at 09:27 AM I would suggest to look up TryStrToInt. But that is just the beginning. What happens if you add 1 to 999.9999? Are there rules for those grouping dots? If the dots are always at the same place you could remove them before conversion and put them back in after your math and reconversion to string. Share this post Link to post
SwiftExpat 33 Posted Thursday at 09:47 AM (edited) 34 minutes ago, Henry Olive said: 600.005.0011 split the string based on the delimiter for the last string in the list, ('0011') convert to integer (11) and increment (12) convert the int back to a string ('12') compare the lengths and then loop to add in the padding zeros ('0012') concate the list back to 1 string Edited Thursday at 09:48 AM by SwiftExpat note to concat Share this post Link to post
PeterBelow 119 Posted Thursday at 11:53 AM 2 hours ago, Henry Olive said: Good Day, MyCode in Database = VARCHAR(20) MyCode could be (120 or 250) like 3 digit Integer, or (200.001 or 600.010) there is a dot between numbers, or (500.005.0010 or 100.010.1500) there are 2 dots between numbers I need to Increase MyCode by 1 that is if MyCode = 100 then requested result = 101 if MyCode = 300.001 then requested result = 300.002 if MyCode = 600.005.0010 then requested result = 600.005.0011 How can i do that Do it on the string itself, like you learned addition in school. function incrementID(const aID: string):string; var ch: Char; N: Integer; begin Result := aID; N:= Length(Result); while N > 0 do begin ch := Result[N]; case ch of '0'..'8': begin Result[N] := Succ(ch); Break; end; '9': begin Result[N] := '0'; Dec(N); end; '.': Dec(N); else raise Exception.CreateFmt('Invalid character "%s" in ID "%s" at position %d.', [ch, aID, N]); end; {case ch} end; {while} end; 2 Share this post Link to post
Henry Olive 4 Posted Thursday at 12:21 PM Thank You Sherlock, SwiftExpat Thank You SO MUCH Peter Share this post Link to post
mvanrijnen 81 Posted Thursday at 02:41 PM (edited) [wrong topic] Edited Thursday at 02:43 PM by mvanrijnen Share this post Link to post
Serge_G 60 Posted Thursday at 03:35 PM (edited) Hi, yes you can Split procedure TForm23.Button1Click(Sender: TObject); var S : TArray<String>; begin S:=Edit3.Text.Split(['.']); S[length(S)-1]:=Format('%.3d',[(StrToInt(S[Length(S)-1])+1)]); Edit3.Text:=String.Join('.',S); end; Edited Thursday at 03:41 PM by Serge_G Share this post Link to post
Fr0sT.Brutal 634 Posted Thursday at 03:44 PM Quote Edit3.Text:=String.Join('.',[S[0],S[1],S[3]]); Edit3.Text:=String.Join('.',S); ? 1 Share this post Link to post
Serge_G 60 Posted Thursday at 03:50 PM (edited) @Fr0sT.Brutal, code was edited during your post. Just a thing, this MyCode = 600.005.0010 then requested result = 600.005.0011 should not work you have to manage a way to have the good formatstring something like procedure TForm23.Button1Click(Sender: TObject); var S : TArray<String>; fmt : string; begin S:=Edit3.Text.Split(['.']); fmt:='%.'+Length(S[Length(S)-1]).tostring+'d'; S[length(S)-1]:=Format(fmt,[(StrToInt(S[Length(S)-1])+1)]); Edit3.Text:=String.Join('.',S); end; Edited Thursday at 04:00 PM by Serge_G 1 Share this post Link to post