开发者

Convert multiline string to single line string

I'm using Google App Engine and I need to put a multiline string in the datastore. Unfortunately, GAE does not allow that.开发者_StackOverflow社区 I need this string to be multiline, so is there any way to convert a multiline string to a single line string and store it?


You don't need no conversion:

google.appengine.ext.db.StringProperty(multiline=True)


Replace all newlines with "\n", and replace all "\" with "\\", just like the way you do with string literals:

def encode(s):
    return s.replace("\\", "\\\\").replace("\n", "\\n")
def decode(s):
    return s.replace("\\\\", "\\").replace("\\n", "\n")
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜