Page 1 of 1

conversion of a string

Posted: Fri Jan 21, 2022 11:24 am
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?

Re: conversion of a string

Posted: Fri Jan 21, 2022 4:17 pm
by Antonio Linares
Dear Silvio,

Search for "," only, no spaces

Re: conversion of a string

Posted: Fri Jan 21, 2022 6:02 pm
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