conversion of a string

conversion of a string

Postby Silvio.Falconi » Fri Jan 21, 2022 11:24 am

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 view
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 November 2023 - January 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
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: conversion of a string

Postby Antonio Linares » Fri Jan 21, 2022 4:17 pm

Dear Silvio,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: conversion of a string

Postby James Bott » Fri Jan 21, 2022 6:02 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 92 guests