Home Database Mysql Tutorial 解释一下为什么数据文件最好采用单字符作为分隔符

解释一下为什么数据文件最好采用单字符作为分隔符

Jun 07, 2016 pm 03:22 PM
one time Why character data document most explain use

本文出处:http://blog.csdn.net/chaijunkun/article/details/17279565,转载请注明。由于本人不定期会整理相关博文,会对相应内容作出完善。因此强烈建议在原始出处查看此文。 距离上次写技术博客已经有半年时间了,年尾我觉得有必要写点东西总结一下经验,

本文出处:http://blog.csdn.net/chaijunkun/article/details/17279565,转载请注明。由于本人不定期会整理相关博文,会对相应内容作出完善。因此强烈建议在原始出处查看此文。

距离上次写技术博客已经有半年时间了,年尾我觉得有必要写点东西总结一下经验,分享给大家。近期在做一个数据同步的项目,从数据中心拿到定时分发的导出文件后,按照固定字段的含义再逐行解析,然后进一步分析后倒入到我这边的数据库。需求简单就是这样,我们来看个例子:

 2013-09-29^_^21635265^_^测试标题^_^10^_^20^_^15

假设上面的例子是文本数据的其中一行。在这个例子中,列分隔符采用的是^_^(注意,是多字符的),字段定义分别是 
发布日期^_^文章ID^_^文章标题^_^评论数^_^点击数^_^顶数
Copy after login
考虑到对数据中心的信任,我们忽略了“发布日期”、“文章ID”、“评论数”、“点击数”和“顶数”这些字段的非法情况,而将重点放在了分析标题上,因为标题是用户指定的,而可以输入任何可见字符,因此我们还考虑到了在文章中包含我们的分隔符的情况,所以在data.splite()之后采用了掐头去尾的算法,前两个字段正常分析,然后倒着来,从“顶数“,”点击数”和“评论数”分析,剩下的就是标题了。可是我们只考虑了标题中如下形式:

测试标题^_^、测试^_^标题、^_^测试标题

而没有考虑到这样的情况:

测试标题^_

也就是说标题中的末尾带有一半分隔符,这样从逻辑上和真正分隔符的前一半正好能拼成一个合理的分隔符,如:

2013-09-29^_^21635265^_^测试标题^_^_^10^_^20^_^15

所以在拆分字段的时候评论数字段就被拆成了“_^10”,这种情况下是没有办法将其转换为Integer类型的,故而报错。

说起来在这个项目中采用什么样的分隔符还是很早前其他同事定的,直到发生这个问题才觉得有必要改成单个字符,这样就不会产生歧义了。

后来在我用Excel导入其它数据进行分析的时候发现它早就注意到这个问题了,在指定自定义分隔符的时候只允许采用单字符:

\

\

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

WordPress site file access is restricted: Why is my .txt file not accessible through domain name? WordPress site file access is restricted: Why is my .txt file not accessible through domain name? Apr 01, 2025 pm 03:00 PM

Wordpress site file access is restricted: troubleshooting the reason why .txt file cannot be accessed recently. Some users encountered a problem when configuring the mini program business domain name: �...

Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Apr 01, 2025 pm 03:06 PM

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

How to use binance security validator How to use binance security validator Mar 27, 2025 pm 04:48 PM

Want to keep your Binance account safe? This article details how to use Binance security authenticator (such as Google Authenticator), including downloading and installing, enabling settings, backup keys, and daily usage tips to effectively prevent theft of the account.

Django time range query: Why does the __range parameter not contain an end date? Django time range query: Why does the __range parameter not contain an end date? Apr 01, 2025 pm 04:06 PM

Question about Django time range query: Why is the end date not included? When using Django for database queries, we often need to use the time...

Typecho route matching conflict: Why is my /test/tag/his/10086 matching TestTagIndex instead of TestTagPage? Typecho route matching conflict: Why is my /test/tag/his/10086 matching TestTagIndex instead of TestTagPage? Apr 01, 2025 am 09:03 AM

Typecho routing matching rules analysis and problem investigation This article will analyze and answer questions about the inconsistent results of the Typecho plug-in routing registration and actual matching results...

Failed to obtain Taobao order data: Why do you still jump to the login page with cookies and URL parameters? Failed to obtain Taobao order data: Why do you still jump to the login page with cookies and URL parameters? Apr 02, 2025 am 06:54 AM

Difficulty in obtaining Taobao order data: Bypassing the challenge of login page Many friends will encounter a difficult problem when trying to obtain information about purchased products on Taobao:...

Why does a box appear when adding Chinese characters to a picture in PHP? How to solve it? Why does a box appear when adding Chinese characters to a picture in PHP? How to solve it? Apr 01, 2025 pm 12:12 PM

The problem of boxing when adding Chinese characters to images is found when PHP adds Chinese characters to watermarks. When adding Chinese characters to images, many developers will encounter a strange problem: Chinese characters become...

See all articles