• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

Remove Element from Character Array

Is there a command to remove one element from a character array ?
For example, if I have a dynamic char array that is 7 elements long, the members of which are RENEWAL. I want to remove the fourth element, Array[3], (second E,) and leave a six element character array whose elements are RENWAL.
0
ChLa
Asked:
ChLa
  • 5
  • 3
1 Solution
 
ChLaAuthor Commented:
I tried using Delete(StringName, ElementNumber, 1)
but get an "incompatible types" error
0
 
epasquierCommented:
no, you can't delete elements in array the same way you can do it with strings.
Besides, even with strings that is costly operation.

With arrays, you have to move elements 'manually'
Move( Array[i+1], Array[i], (High(Array)-i)*SizeOf(Char) );

Open in new window

0
 
epasquierCommented:
100$ Question : Why are you using Char arrays instead of Strings, which have higher level functions very convenient to use ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ChLaAuthor Commented:
I didn't think a string array was applicable to single letters, never though of it
0
 
ChLaAuthor Commented:
So, I could use a single string as if it were a char array ? I could copy a subset of first string to another empty string, and then remove one letter at a time ?
0
 
epasquierCommented:
> So, I could use a single string as if it were a char array ?
Yes !
Var
  MyCharSet:String;
  P:Integer;
begin
  MyCharSet:='ABCDEF';
  // Remove 'C' from above set
  P:=Pos('C',MyCharSet);
  if P>0 Then Delete(MyCharSet,P,1);
  // Now , MyCharSet = 'ABDEF'
  // access elements exactly like an array, except that first char is in position 1, not 0 : 
  // 1st : MyCharSet [ 1 ] 
  // last : MyCharSet [ Length(MyCharSet) ] 
end;

Open in new window

0
 
ChLaAuthor Commented:
Ok, cool, looks good. Let me try it. May take a while...many distractions here.
0
 
ChLaAuthor Commented:
Thank You
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now