Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete last char

Tags:

delphi

How to delete last character of String with substring or anything ?

For example;

var
  query : String;
begin
  query:= 'test=1&line=5&'; 
end;

Output must be :

query -> test1&line=5
like image 456
Dauezevy Avatar asked Mar 17 '15 14:03

Dauezevy


People also ask

How do you delete the last few characters?

Remove last N characters from string Using negative slicing Last character in string has index -1 and it will keep on decreasing till we reach the start of the string. So to remove last 3 characters from a string select character from 0 i.e. to -3 i.e.

How do I remove the last 3 letters from a string?

Use the String. slice() method to remove the last 3 characters from a string, e.g. const withoutLast3 = str. slice(0, -3); . The slice method will return a new string that doesn't contain the last 3 characters of the original string.


2 Answers

A third option is this:

SetLength(Query,LENGTH(Query)-1)
like image 189
HeartWare Avatar answered Sep 23 '22 07:09

HeartWare


Try this:

var
  query : String;
begin
  query:= 'test=1&line=5&';
  delete(query,length(query),1);
like image 37
Mike Jablonski Avatar answered Sep 21 '22 07:09

Mike Jablonski