Source language: Translate to:

Please help me... to convert string

General questions about NeoBook

Moderator: Neosoft Support

Please help me... to convert string

Postby franco21 » Sat Jul 22, 2017 10:33 pm

What I need to do is:

Read an extension file csv, whose columns are separated by: (semicolon)
The file has x number of rows with data being the first row the field titles.
In row 1 has the following values ​​in each column given that they are the titles:

Colomna 1 = Title
Column 2 = Content
Column 3 = Listing Regions
Column 4 = Listing Categories
Column 5 = _filled
Column 6 = _featured
Column 7 = _job_location
Column 8 = _application
Column 9 = _claimed
Column 10 = _phone
Column 11 = geolocated
Column 12 = geolocation_city
Column 13 = geolocation_country_long
Column 14 = geolocation_country_short
Column 15 = geolocation_formatted_address
------------------------------------------
Column 16 = geolocation_lat
Column 17 = geolocation_long
------------------------------------------
Column 18 = geolocation_state_long
Column 19 = geolocation_state_short
Column 20 = geolocation_street
Column 21 = geolocation_street_number

Column 16 belongs to latitude and has a value like the following (without the quotation marks) "-350.555.555"
The same happens with column 17 which is the length presenting the value of the same format.

I need to replace the format of both columns (16/17) so that it is like this "-35.0555555"
That is to say that it eliminates the separating points and that it places a point only after the second value respecting the
Sign before the first number

Finally you have to rewrite line by line all the modified file.

Please if someone can give me a hand I will really appreciate it urge me to solve this
franco21
 
Posts: 122
Joined: Tue Jan 14, 2014 3:46 pm

Re: Please help me... to convert string

Postby Gaev » Sun Jul 23, 2017 5:38 am

Franco21:

Do the values in columns 16 and 17 ALWAYS contain 3 digits for the sub-fields ? ... or can they also be ...

-50.555.555
350.0.60
etc. etc.

... if not fixed length (of 3 digits each), please give examples of what the transformed values should look like for each possible case.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Please help me... to convert string

Postby franco21 » Sun Jul 23, 2017 6:05 am

HI

all comumna 16 adn 17 content number

example
-356.222.222
-698.899.655
-226.555.999
etx

y need convert this valor one by one into all columna to number to this format

-35.6222222
-69.8899655
-22.6555999

the format -###.###.### to format -##.######
franco21
 
Posts: 122
Joined: Tue Jan 14, 2014 3:46 pm

Re: Please help me... to convert string

Postby Gaev » Sun Jul 23, 2017 7:15 am

franco21:

Thank you for the details; assuming that there is ALWAYS a negative sign (or at least a sign) in the front ...
Code: Select all
... say that the content of column 16 is in variable called [myColumn16]
StrReplace "![myColumn16]" "!." "" "[Result]" ""
... [Result] will now contain minus sign followed by 9 digits
StrIns "!." "[Result]" "4" "[myColumn16]"
... [myColumn16] will now contain minus sign followed by 2 digits, a decimal point and then the rest of the digits

... same two lines for [myColumn17].

You can parse each line (row) in the csv file using ...
Code: Select all
StrParse "[thisRow]" ":" "[myColumn]" "[elementCount]"

... which will create an arrayed variable [myColumn1], [myColumn2], .... up to [myColumn21]

After changing columns 16 and 17, you can recreate the line with ...
Code: Select all
SetVar "[thisRow]" "![myColumn1]:[myColumn2]: etc. etc. :[myColumn21]"

... and you can read each line in your file with
Code: Select all
FileLen "nameOfYourCSVFileHere" "[LinesCount]"
Loop "2" "[LinesCount]" "[thisLineNumber]"
   FileRead "nameOfYourCSVFileHere" "[thisLineNumber]" "[thisRow]"
   ... insert code shown above to extract and transform columns 16 and 17 within [thisRow]
   FileWrite "nameOfYourCSVFileHere" "[thisLineNumber]" "[thisRow]"
EndLoop

... note that you can also write the result to another file (use "Append" instead of [thisLineNumber])

Warning: Above code was not verified ... so it may contain typo errors.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Please help me... to convert string

Postby franco21 » Sun Jul 23, 2017 1:29 pm

Thanks for your help bad not found

run this code bad columna 16 and 17 not convert format numbers

example after > -345.555.555
before run code > -345.555.555
franco21
 
Posts: 122
Joined: Tue Jan 14, 2014 3:46 pm

Re: Please help me... to convert string

Postby Gaev » Sun Jul 23, 2017 2:33 pm

JUST EDITED ... StrParse command now changed to split on semicolon (was split on colon before) !!!

franco21:
run this code bad columna 16 and 17 not convert format numbers

example after > -345.555.555
before run code > -345.555.555

Let us try and debug it ... start with code that looks like this ...
Code: Select all
FileLen "nameOfYourCSVFileHere" "[LinesCount]"
Loop "2" "[LinesCount]" "[thisLineNumber]"
   FileRead "nameOfYourCSVFileHere" "[thisLineNumber]" "[thisRow]"
   ... extract and transform column 16
   StrParse "[thisRow]" "!;" "[myColumn]" "[elementCount]"
   AlertBox "Column16 Before" "[myColumn16]"
   StrReplace "![myColumn16]" "!." "" "[Result]" ""
   AlertBox "Result" "[Result]"
   StrIns "!." "[Result]" "4" "[myColumn16]"
   AlertBox "Column16 After" "[myColumn16]"
EndLoop


Run this code with just 2 rows (including header) of data ... post the contents of the AlertBox commands
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Please help me... to convert string

Postby franco21 » Mon Jul 24, 2017 9:22 am

The debug test that you sent me worked perfectly, now when I generate the final code again and I run the column 16 and 17 are the same without transforming, it gives me the break point every 3 digits while the test code the alertbox came out corrected. ...

This is my code to run

FileLen "plantilla-final.csv" "[LinesCount]"
Loop "2" "[LinesCount]" "[thisLineNumber]"
SetVar "[thisRow]" "![myColumn1];[myColumn2];[myColumn3];[myColumn4];[myColumn5];[myColumn6];[myColumn7];[myColumn8];[myColumn8];[myColumn9];[myColumn10];[myColumn11];[myColumn12];[myColumn13];[myColumn14];[myColumn15];[myColumn16];[myColumn17];[myColumn18];[myColumn18];[myColumn20];[myColumn21]"

FileRead "plantilla-final.csv" "[thisLineNumber]" "[thisRow]"
StrParse "[thisRow]" "!;" "[myColumn16]" "[elementCount]"
StrReplace "![myColumn16]" "!." "" "[Result]" ""
StrIns "!." "[Result]" "4" "[myColumn16]"
StrReplace "![myColumn16]" "!." "" "[Result]" ""
StrIns "!." "[Result]" "4" "[myColumn16]"
StrParse "[thisRow]" "!;" "[myColumn17]" "[elementCount]"
StrReplace "![myColumn17]" "!." "" "[Result]" ""
StrIns "!." "[Result]" "4" "[myColumn17]"
StrReplace "![myColumn17]" "!." "" "[Result]" ""
StrIns "!." "[Result]" "4" "[myColumn17]"

FileWrite "testeo.csv" "[thisLineNumber]" "[thisRow]"

EndLoop
franco21
 
Posts: 122
Joined: Tue Jan 14, 2014 3:46 pm

Re: Please help me... to convert string

Postby Gaev » Mon Jul 24, 2017 10:33 am

EDITED LATER - added code to copy line 1 of csv file to output file

franco21:

Try this code ...
Code: Select all
FileLen "plantilla-final.csv" "[LinesCount]"

... copy header line for csv file
FileRead "plantilla-final.csv" "1" "[thisRow]"
FileWrite "testeo.csv" "1" "[thisRow]"

Loop "2" "[LinesCount]" "[thisLineNumber]"

   FileRead "plantilla-final.csv" "[thisLineNumber]" "[thisRow]"
   ... next command will setup [myColumn1] to [myColumn21]
   StrParse "[thisRow]" "!;" "[myColumn]" "[elementCount]"

   StrReplace "![myColumn16]" "!." "" "[Result]" ""
   StrIns "!." "[Result]" "4" "[myColumn16]"

   StrReplace "![myColumn17]" "!." "" "[Result]" ""
   StrIns "!." "[Result]" "4" "[myColumn17]"

   SetVar "[thisRow]" "![myColumn1];[myColumn2];[myColumn3];[myColumn4];[myColumn5];[myColumn6];[myColumn7];[myColumn8];[myColumn8];[myColumn9];[myColumn10];[myColumn11];[myColumn12];[myColumn13];[myColumn14];[myColumn15];[myColumn16];[myColumn17];[myColumn18];[myColumn18];[myColumn20];[myColumn21]"

   FileWrite "testeo.csv" "[thisLineNumber]" "[thisRow]"

EndLoop
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Please help me... to convert string

Postby virger » Mon Jul 24, 2017 4:40 pm

Creo asi se soluciona:
1) FUNCION (JsSepare)
Code: Select all
{NeoBook Function}
Version=5,80
Language=JScript
Param=[%str]|Variable|String
Param=[%ret]|Variable|Return Value
{End}
var str  = nbgetvar("[%str]");
var vTmp = str.match(/[-|+](\d+[,|.])+\d+/gm);

if (vTmp && vTmp.length > 1){
   for(var i = 0; i < vTmp.length; i++){
      var vSin = vTmp[i].replace(/\./g, '');
      var vSin = vSin.slice(0, 3)+ "." + vSin.slice(3);
      str = str.replace(vTmp[i],vSin)   ;
}
}

nbsetvar("[%ret]",str);


2) Un boton con este codigo
Code: Select all
var "[LineIn]" "MOTOVERDE;Repuestos para Motos;Ciudad Autonoma de Buenos Aires;Motos;0;0;Av. Pueyrredón 933, Ciudad Autonoma de Buenos Aires;motoverde01@hotmail.com;1;011 49661991;1;Ciudad Autonoma de Buenos Aires;Argentina;AR;Av. Pueyrredón 933, Ciudad Autonoma de Buenos Aires;-34.599.446;-58.403.861;Buenos Aires;BA;933;Av. Pueyrredón"

Call "JsSepare" "[lineIn]" "[lineOut]"

alertbox "RESULTADO" "[LineIn]|[LineOut]"


Nos eliminaron de la Gold Cup
Hasta la proxima
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 518
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central


Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 2 guests