New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capitalize initials of all names in a string #48
Comments
I verified that
|
I'm sorry if you feel this is rude, but I have a question. Csvq is not originally designed to do very complex processing, and there are usually other good solutions for such things. There is no need to try to do everything with one tool when there are many other great tools in the world. By the way, you can get the results with the current features of csvq. For example, you can create a user-defined function to get the result you want. Declare the user-defined function in a file named "capitalize.sql". DECLARE CAPITALIZE FUNCTION (@str) AS BEGIN
DECLARE @result := '';
DECLARE @list := REGEXP_FIND_ALL(@str, '\w+');
DECLARE @i := 0;
WHILE TRUE
DO
DECLARE @item := JSON_VALUE('[' || @i || '][0]', @list);
IF @item IS NULL THEN
BREAK;
END IF;
IF 0 < LEN(@item) THEN
IF 0 < LEN(@result) THEN
@result := @result || ' ';
END IF;
@result := @result || UPPER(SUBSTRING(@item FROM 1 FOR 1));
END IF;
IF 1 < LEN(@item) THEN
@result := @result || SUBSTRING(@item FROM 2);
END IF;
@i := @i + 1;
END WHILE;
RETURN @result;
END; And run a sql with the SOURCE command.
|
Thank you for this solution. I don't think your response was rude at all. I do have a specific purpose. I want to capitalize the initials of names in a column that contains full names in mixed case. ;-) I think this is not such a complicated problem and so I prefer to use csvq than resort to another tool or a lower level programming language like Rust, Java, or heaven forbid, Python. I've yet to use user defined functions in csvq and I had forgotten that csvq supported them. I have read several sections of the csvq documentation many times, but this time I somehow overlooked the section on user defined functions. I sometimes confuse Miller and csvq's features and so mistakenly thought that Miller had user defined functions, but csvq did not. |
By the way, for what it's worth, as far as I could tell, SQLite string functions can't do this, either, and SQLite doesn't support user defined functions except those in the form of loadable modules implemented in C. |
Is |
You can also use the function LIST_ELEM.
I'd like to implement composite types of Array and Map, and syntax and functions to handle them, but it may take a while. |
I'll be patient, then. |
Thanks for your response. The function to capitalize will be provided in the future, but regular expressions will remain as they are now. |
Thank you. I was just thinking about how to load user defined functions. I'm satisfied with the user defined |
I implemented user defined function
|
- Support column name wildcard for tables. ([GitHub #68](#68)) - Add a built-in function. - TITLE_CASE ([GitHub #48](#48)) - Modify integer and float handling. - Fixed a bug in the conversion between integer and float. - Intuitive handling of integer and float. - Allow exponential notation for float.
TITLE_CASE function has been included in version 1.17.0. |
Given a string that contains multiple lower case names (words), how might I capitalize only the initial letter of these names?
I think that the existing set of string functions in csvq cannot perform this operation. However, this can be done by applying a PCRE2 regular expression substitution which converts all initials to upper case.
Unfortunately, according to Regular Expressions 101, Golang does not support the PCRE2 substitution operator
\u
, so I presume that the new regular expression functionsREGEXP_REPLACE
in csvq v1.14.1-pr.1 likewise also cannot perform this operation. If this is the case, would you consider implementing a specific string function or generic set of string functions to capitalize all words in a string?The text was updated successfully, but these errors were encountered: