使每个单词第一个字母大写Sqlite

时间:2018-04-25 09:08:14

标签: sqlite

我希望能够更新字符串大写中的每个单词。

我可能有什么:

the dog is brown

我想要的是什么:

The Dog Is Brown

现在我在发布之前在这里搜索过并遇到了这个问题:SQLite Updating first letter to be upper case

使用提供的已接受答案查询:UPPER(SUBSTR(field, 1, 1)) || SUBSTR(field, 2)这会将第一个单词更新为大写不是全部吗?

是否可以添加一些内容以使其适用于所有单词?

谢谢!

3 个答案:

答案 0 :(得分:1)

您可以使用以下内容作为基础: -

测试表创建

DROP TABLE IF EXISTS sentences;
CREATE TABLE IF NOT EXISTS sentences (sentence TEXT);

加载一些测试数据

INSERT INTO sentences
VALUES 
    ('the dog is brown'),('pigs are pink'),('polar bears are white'),('orangutans are orange'),('zebras are black and white');

表格如下: -

enter image description here

查询

SELECT 
    substr(
        replace(
            replace(
                replace(
                    replace(
                        replace(
                            replace(
                                replace(
                                    replace(
                                        replace(' '||sentence,' a',' A')
                                    ,' b',' B'),
                                ' c',' C'),
                            ' d',' D'),
                        ' e',' E'),
                    ' f',' F'),
                ' g',' G'),
            ' h',' H'),
            -- ..........
        ' t',' T')
        -- .............
    ,2) AS converted
FROM sentences
  • 这是以a-h和t
  • 开头的单词
  • 它添加了一个空格,允许按照' '||sentence转换第一个单词,然后在完成所有替换substr(........,2)后删除空格。

结果

enter image description here

答案 1 :(得分:1)

str.split(' ').map((it, i) => {
  return (it[0].toUpperCase() + it.slice(1))
}
).join(' ')

答案 2 :(得分:-1)

true
true
added
[ü]
相关问题