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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 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)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
How to display child categories on archive page of parent categories How to display child categories on archive page of parent categories Apr 19, 2025 pm 11:54 PM

Do you want to know how to display child categories on the parent category archive page? When you customize a classification archive page, you may need to do this to make it more useful to your visitors. In this article, we will show you how to easily display child categories on the parent category archive page. Why do subcategories appear on parent category archive page? By displaying all child categories on the parent category archive page, you can make them less generic and more useful to visitors. For example, if you run a WordPress blog about books and have a taxonomy called "Theme", you can add sub-taxonomy such as "novel", "non-fiction" so that your readers can

Why is the rise or fall of virtual currency prices? Why is the rise or fall of virtual currency prices? Why is the rise or fall of virtual currency prices? Why is the rise or fall of virtual currency prices? Apr 21, 2025 am 08:57 AM

Factors of rising virtual currency prices include: 1. Increased market demand, 2. Decreased supply, 3. Stimulated positive news, 4. Optimistic market sentiment, 5. Macroeconomic environment; Decline factors include: 1. Decreased market demand, 2. Increased supply, 3. Strike of negative news, 4. Pessimistic market sentiment, 5. Macroeconomic environment.

Why does the Spring project cause randomness problems due to circular dependencies when starting? Why does the Spring project cause randomness problems due to circular dependencies when starting? Apr 19, 2025 pm 11:21 PM

Understand the randomness of circular dependencies in Spring project startup. When developing Spring project, you may encounter randomness caused by circular dependencies at project startup...

Why is the return value empty when using RedisTemplate for batch query? Why is the return value empty when using RedisTemplate for batch query? Apr 19, 2025 pm 10:15 PM

Why is the return value empty when using RedisTemplate for batch query? When using RedisTemplate for batch query operations, you may encounter the returned results...

Why can't JavaScript directly obtain hardware information on the user's computer? Why can't JavaScript directly obtain hardware information on the user's computer? Apr 19, 2025 pm 08:15 PM

Discussion on the reasons why JavaScript cannot obtain user computer hardware information In daily programming, many developers will be curious about why JavaScript cannot be directly obtained...

Why does the redisTemplate.opsForList().leftPop() method not support passing in parameters to pop up multiple values ​​at once? Why does the redisTemplate.opsForList().leftPop() method not support passing in parameters to pop up multiple values ​​at once? Apr 19, 2025 pm 10:27 PM

Regarding the reason why RedisTemplate.opsForList().leftPop() does not support passing numbers. When using Redis, many developers will encounter a problem: Why redisTempl...

Steps to add and delete fields to MySQL tables Steps to add and delete fields to MySQL tables Apr 29, 2025 pm 04:15 PM

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

See all articles