-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSV trim-option does not trim spaces at the end of strings #57959
Comments
With the attached dataset I confirm the problem also in QGIS 3.34.8, 3.38.0 OSGeo4W win 11 |
Hi @wvdbee in some way your CSV is not optimal, because you have double quotes even when you don't need them. If you have something like this
the trimming seems to work It should probably work in your case, too, but maybe if you have the double quotes it's like telling QGIS that those are not "normal" spaces, but that those spaces are part of the values. Best regards |
Hello @aborruso Thank you for your insight. But I think you're not completely right. Couple of remarks: RFC4180 says
Which means that aaa,bbb,ccc is not equal to aaa,bbb ,ccc. Second column in the second example contains 4 characters and in the first example it contains 3 characters. So double quotes are not required to add spaces to a field. Spaces and quotes are not explicitly linked to each other. Second: in fact the file is a DSV and not a CSV (delimiter separated and not comma separated). DSV is free regarding the way it is formatted. Thankfully QGIS supports all kinds of DSV and not specifically RFC4180-complient CSV. DSV-formatted files can contain al sorts of intended and unintended data. And there are no explicit formatting rules, I guess. So you can not do assumptions regarding the meaning of quotes in DSV-files. Third, my main point: I interpret the Trim Fields-check box as a post-processing option: whenever a field contains spaces around, then trim these spaces. Which means, it is up to the user to decide whether or not spaces are intended or not. Back to my example: in RFC4180-complient csv aaa,bbb ,ccc the space is also part of the data. Even then it is up to the user to decide whether or not the space is intentionally or unwanted. The trim-check box then comes in quit usefull to trim unwanted spaces. I think it should work for both the quoted and unquoted fields. By the way, the example data is is not mine but is a download from our national statistics agency. Spaces are unwanted and not intended. I quess it is a flaw in one of their download formats. And, yes, I know I can preprocess the CSV/DSV myself. But what then is the purpose of the check box? :-) https://statline.rivm.nl/portal.html?_la=nl&_catalog=RIVM&tableId=50120NED&_theme=93 |
Hi @wvdbee
I don't think I'm completely in the right, nor did I refer to rfc4180. I do not like CSV with unnecessary double quotes, I therefore cleaned it up and saw that it worked better. From here on, a QGIS developer, who is reading this thread, has some useful elements to make a good choice. |
What is the bug or the crash?
The trim fields-option does not trim a string field.
Steps to reproduce the issue
Settings:
Some fields contain loads of training spaces
Settings in Add CSV-Layer-window
Alas, spaces have not been trimmed.
Demo-set
50120NED_TypedDataSet_25062024_172055.zip
Versions
<style type="text/css"> p, li { white-space: pre-wrap; } </style>Active Python plugins
AutomaticBackup-master
1.0
BGTImport
3.18
changeDataSource
3.1
create_layer_from_selected_features
1.2
geo_sim_processing
1.2.0
GroupStats
2.2.7
mmqgis
2021.9.10
pcraster_tools
0.3.0
pdokservicesplugin
5.0.1
precisioncursor4qgis-main
1.1.D
processing_saga_nextgen
1.0.0
qgis_resource_sharing
1.0.0
quick_map_services
0.19.34
SelectWithin
0.4
slyr_community
5.0.0
StreetView
3.2
topo_tijdreis
1.0
db_manager
0.1.20
MetaSearch
0.3.6
processing
2.12.99
Supported QGIS version
New profile
Additional context
No response
The text was updated successfully, but these errors were encountered: