Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4050168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:02:11+00:00 2026-05-20T14:02:11+00:00

I have a program which works with strings (Pascal). After reading a string if

  • 0

I have a program which works with strings (Pascal). After reading a string if the first char is not a letter then I need to delete all first characters until the first is a letter. I have tried to write it several times, but always it deletes all string or nothing.

If program reads “123%^&abc” then result should be “abc”
In ASCII table letters are from 65..90 and from 97..122

This is how far I am:

variables    a: set of 65..90;
             b: set of 97..122;
-------------------
  bool:=false;
  While (bool=false) do
  begin
    Writeln(s[1]);
    If (Ord(s[1]) in a) or (Ord(s[1]) in b) then
    begin
    bool:=true;
    end else
    delete(s,1,1);
  end;

I don’t understand why it does not work?
Can you help me with this little procedure? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:02:12+00:00Added an answer on May 20, 2026 at 2:02 pm

    You could do

    function RemoveNonAlphaASCIIFromStart(const Str: AnsiString): AnsiString;
    const
      ALPHA = ['A'..'Z', 'a'..'z'];
    var
      i: Integer;
      firstIndex: integer;
    begin
      result := '';
      firstIndex := 0;
      for i := 1 to length(Str) do
        if Str[i] in ALPHA then
        begin
          firstIndex := i;
          break;
        end;
      if firstIndex > 0 then
        result := Copy(Str, firstIndex, length(Str));
    end;
    

    or, as a procedure

    procedure RemoveNonAlphaASCIIFromStart(var Str: AnsiString);
    const
      ALPHA = ['A'..'Z', 'a'..'z'];
    var
      i: Integer;
      firstIndex: integer;
    begin
      firstIndex := 0;
      for i := 1 to length(Str) do
        if Str[i] in ALPHA then
        begin
          firstIndex := i;
          break;
        end;
      if firstIndex > 0 then
        Delete(Str, 1, firstIndex - 1)
      else
        Str := '';
    end;
    

    For more sophisticated methods, that also work with Unicode Delphi, see my answer to a similar question. [This removes all non-alpha chars from the string.]

    So, why doesn’t your algorithm work? Well, it should work, and it works for me. But notice that it can be written in the slightly more elegant form

    const
      ALPHA = ['A'..'Z', 'a'..'z'];
    
    while true do
      if (length(s) = 0) or (s[1] in ALPHA) then
        break
      else
        delete(s, 1, 1);
    

    One problem, however, with the OP’s original code is that it will fail if s is the empty string. Indeed, then s[1] doesn’t exist. It won’t work either if s consists entirely of non-alpha characters (e.g. '!"#¤%).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies if this has been asked before. I have some data which I need
Scratching my head here: I have an application which works fine in Debug+Release if
I have problem with my Java program. How I read xml -file which has
I've written a Java program which scrapes some content from a web page. It
I have a very simple WCF program where I have a simple self-host and
I have made the following method which runs hard-coded xPath queries in a hard-coded
I have a very very simple program that parses a csv file that has
I'm writing a server program in Java that will allow users to submit jobs
Im new to website development and design so apologize in advance if the question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.