Remove the first leading zero - trim

I'm trying to delete only the first zero from the values of a field which now are: 00,01,02,03 etc and I'm using this function: string_trim['0', begin].
The problem with it is that it works for all the values but not for 00, since it removes everything and in the results I receive a NULL value.
Is there any other option in order to remove only the first zero?
Thank you.

Although You did not mention it in which programming language you are asking php or mysql.But below is the hint for your issue.
Split this string into array by comma ( , ).
loop through each array and remove first zero ( right(1) or trim(STRing , '0') )
Then merge array into string by comma separated.

For DataStage this would be a solution for a Transformer stage
IF left(field,1) = "0"
THEN file[2,len(field) - 1)]
ELSE field

Related

SQLite replace() specified character and next character

I have a database with a Username column.
There are multiple section signs followed by numbers §# that format the name.
I have to make sure all names are unique, but I want to disregard the formatting character pairs.
I was going to use,
SELECT * FROM Users WHERE replace(lower(Username),'§%','') = 'name';
but I realized that would look for the percent sign and not act as a wildcard. I could really use some help.
Use a combination of INSTR and SUBSTR to isolate the name before comparing it:
SELECT *
FROM Users
WHERE LOWER(SUBSTR(Username, 1, INSTR(Username, '§%') - 1)) = 'name';

Postgres's query to select value in array by index

My data is string like:
'湯姆 is a boy.'
or '梅isagirl.'
or '約翰,is,a,boy.'.
And I want to split the string and only choose the Chinese name.
In R, I can use the command
tmp=strsplit(string,[A-z% ])
unlist(lapply(tmp,function(x)x[1]))
And then getting the Chinese name I want.
But in PostgreSQL
select regexp_split_to_array(string,'[A-z% ]') from db.table
I get a array like {'湯姆','','',''},{'梅','','',''},...
And I don't know how to choose the item in the array.
I try to use the command
select regexp_split_to_array(string,'[A-z% ]')[1] from db.table
and I get an error.
I don't think that regexp_split_to_array is the appropriate function for what you are trying to do here. Instead, use regexp_replace to selectively remove all ASCII characters:
SELECT string, regexp_replace(string, '[[:ascii:]~:;,"]+', '', 'g') AS name
FROM yourTable;
Demo
Note that you might have to adjust the set of characters to be removed, depending on what other non Chinese characters you expect to have in the string column. This answer gives you a general suggestion for how you might proceed here.

How can I prevent SQLite from treating a string as a number?

I would like to query an SQLite table that contains directory paths to find all the paths under some hierarchy. Here's an example of the contents of the column:
/alpha/papa/
/alpha/papa/tango/
/alpha/quebec/
/bravo/papa/
/bravo/papa/uniform/
/charlie/quebec/tango/
If I search for everything under /bravo/papa/, I would like to get:
/bravo/papa/
/bravo/papa/uniform/
I am currently trying to do this like so (see below for the long story of why I can't use more simple methods):
SELECT * FROM Files WHERE Path >= '/bravo/papa/' AND Path < '/bravo/papa0';
This works. It looks a bit weird, but it works for this example. '0' is the unicode code point 1 greater than '/'. When ordered lexicographically, all the paths starting with '/bravo/papa/' compare greater than it and less than 'bravo/papa0'. However, in my tests, I find that this breaks down when we try this:
SELECT * FROM Files WHERE Path >= '/' AND Path < '0';
This returns no results, but it should return every row. As far as I can tell, the problem is that SQLite is treating '0' as a number, not a string. If I use '0Z' instead of '0', for example, I do get results, but I introduce a risk of getting false positives. (For example, if there actually was an entry '0'.)
The simple version of my question is: is there some way to get SQLite to treat '0' in such a query as the length-1 string containing the unicode character '0' (which should sort strings such as '!', '*' and '/', but before '1', '=' and 'A') instead of the integer 0 (which SQLite sorts before all strings)?
I think in this case I can actually get away with special-casing a search for everything under '/', since all my entries will always start with '/', but I'd really like to know how to avoid this sort of thing in general, as it's unpleasantly surprising in all the same ways as Javascript's "==" operator.
First approach
A more natural approach would be to use the LIKE or GLOB operator. For example:
SELECT * FROM Files WHERE Path LIKE #prefix || '%';
But I want to support all valid path characters, so I would need to use ESCAPE for the '_' and '%' symbols. Apparently this prevents SQLite from using an index on Path. (See http://www.sqlite.org/optoverview.html#like_opt ) I really want to be able to benefit from an index here, and it sounds like that's impossible using either LIKE or GLOB unless I can guarantee that none of their special characters will occur in the directory name, and POSIX allows anything other than NUL and '/', even GLOB's '*' and '?' characters.
I'm providing this for context. I'm interested in other approaches to solve the underlying problem, but I'd prefer to accept an answer that directly addresses the ambiguity of strings-that-look-like-numbers in SQLite.
Similar questions
How do I prevent sqlite from evaluating a string as a math expression?
In that question, the values weren't quoted. I get these results even when the values are quoted or passed in as parameters.
EDIT - See my answer below. The column was created with the invalid type "STRING", which SQLite treated as NUMERIC.
* Groan *. The column had NUMERIC affinity because it had accidentally been specified as "STRING" instead of "TEXT". Since SQLite didn't recognize the type name, it made it NUMERIC, and because SQLite doesn't enforce column types, everything else worked as expected, except that any time a number-like string is inserted into that column it is converted into a numeric type.

Printing the original string as well as vowels in the string with recursion

I'm trying to write a recursive function that would get some string, as well as the lenght of that string as its parameters, and then print out the original string, as well as the reverse order of the vowels in that string. For example if the string is 'Horse', then the output would be 'Horse eo'.
What I'm having trouble with is how to get the original string printed while still getting the vowels out in a reverse order. I'm writing this function with a pseudocode, and how I'd print out only the reversed vowels would be as following.
MODULE VowelRecursion(String, n)
IF n != 0 THEN
letter := first letter of String
vowel := ""
IF letter == vowel THEN
vowel := letter
ENDIF
VowelRecursion(remainder of String, n-1)
Print(vowel)
ENDIF
ENDMODULE
Like I mentioned, the problem I have is that I can't figure out how to get the original string printed after the vowel finding has been done, as the original string needs to be printed first, and to do that wouldn't it have to be returned first after n gets to 0? The problem with that is that since we're calling the function with remainder of string, that would be just an empty string when n == 0, right?
As this is a problem I need to solve for school, I'm not looking for any ready made solutions, but I'd like to hear where my thought process is going wrong and what sort of methods I could use to achieve what's needed.
Thank you.
You may print letter before descending into the next recursion level, i.e. right before the call to VowelRecursion(remainder of String, n-1).
Print(letter)
VowelRecursion(remainder of String, n-1)
Print(vowel)
You can pass the original string along during the recursion. You don't modify that string but you simply use it when the recursion is done. Also, you can't print a vowel when you find it. You'll need to store them somewhere and only print them when you're done.
This means you should add two more parameter: a parameter that contains the original string and a (computed) string with the vowels found so far (initially empty). As a hint, you can solve this problem with a recursive function that is called VowelRecursion("Horse", "Horse", "", 5). When n = 0, you'll have all the values you need to print the desired result.

flex localization equals character

I'm having problems placing an equals character in my locale file
I have to do something like this:
#greater value
greater_value = the value must be ( >= ) than the corresponding value
but when the thing is displayed in the ui the text after the second equals is missed
how do you place an equals character in a flex locale file?
edit: I have already used, escape characters, ascci code, html codes and unicode unicodes.
You can use unicode character representation:
greater_value = the value must be ( >\u003D ) than the corresponding value
I dont know why but the unicode representation didnt work for me, what I finally did was to use the solution proposed by harry ninh, using the StringUtil.substitute.
There is a little bit tricky way to overcome this problem:
greater_value = the value must be ( {0} ) than the corresponding value
Then in your AS code, use StringUtil.substitute(localeString, ">=");

Resources