开发者

Characters for code-readable files

开发者 https://www.devze.com 2023-04-06 01:54 出处:网络
I\'m making a program, and I want to be able to store questions and answers in a text file. What I\'m doing right now is separating the different question/answer combos by a new line, and separating t

I'm making a program, and I want to be able to store questions and answers in a text file. What I'm doing right now is separating the different question/answer combos by a new line, and separating the questions from the answers by having the questions first, then /// (triple slash) and then the answer. The problem with this is that the user can't enter a triple slash or slashes at the end of the question without messing th开发者_开发知识库e program up.

So what I'm looking for is some character that I can put in that can't be entered by the user in any way shape or form to separate the questions and answers. What I'm leaning towards right now is some unicode symbol like a smiley face, but anything that's more perfect would be appreciated.

As a side question, where should I store this document on Mac OS X? Should it be in application support, or part of the app bundle itself?


There are some well-documented pre-existing text formats you might want to consider. I would look into csv (comma-separated-value), tsv (tab-separated value), json and xml. Most likely xml and json are overkill for you, but they solve this problem nicely, and if you already have libraries for dealing with those in your code stack, you can get going more quickly by using those.

But for a DIY approach, I would recommend tsv. It's hard for users to enter the "TAB" ASCII 09 character in web forms, and you can usually convert to space without losing much information if they do. Then you just have to work out what your record-separator will be; probably on the Mac you will want to use CR (ascii 13), but NL (ascii 10) is a fine choice too.

0

精彩评论

暂无评论...
验证码 换一张
取 消