conversion of a string

Post Reply
User avatar
Silvio.Falconi
Posts: 7169
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 3 times

conversion of a string

Post by Silvio.Falconi »

When I download from Excel into dbf I save on a field a string of name of Teachers
when I have to convert to another archive, I break the surname and name and check if there is a comma

sample
Image

I state the list in excel is created by the end user

on the my function

aTokens := HB_ATokens( cDocente, ", " ,.t.,.t.)
cCognome := alltrim(aTokens[1])
cNome := alltrim(aTokens[2])


however it can happen to find a space before the comma or the space is after the comma
and when it finds these problems it makes me error and exits the program

sample

Code: Select all | Expand

Error occurred at: 21-01-2022, 12:11:27
   Error description: Error BASE/1132  Limiti superati: accesso all'array
   Args:
     [   1] = A   {"VISCHIA ,MICHELA"} length: 1
     [   2] = N   2



How can I avoid this error?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

Re: conversion of a string

Post by Antonio Linares »

Dear Silvio,

Search for "," only, no spaces
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: conversion of a string

Post by James Bott »

Silvio,

You can preprocess the string to remove unwanted characters.

StrTran()

This is a Clipper/Harbour function. See the Clipper Reference Guide here:

https://harbour.github.io/doc/clc53.html

Note that you can look for a substring and do a replace with another string using this function.

cString:= StrTran(cString," ,", ",")

The above looks for any leading spaces followed by a comma and replaces them with just the comma. I would preprocess the entire database using this to clean up user data entry mistakes. In the future it would be better to automatically process user input in the GET to prevent bad formatting from getting into the database.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Post Reply