I have a form with a text-input element.
The user can enter values separated by commas like "a,b,c,d". In my model, there's a List which should then hold these values (which really are a list).
In Thymeleaf, how can I bind such a string and convert it to a list on submit? Is there something like a Converter interface?
In your Model instead of List you can use String to populate the input values. After you get the values, you can do following:
You will probably have a String something like this: "text1, text2, text3...". Then convert it to a List you can do something like this:
String value = "text1, text2, text3..."
List<String> inputs = Arrays.asList(value.split("\\s*,\\s*"));
The regex basically removes the whitespace and the comma. This should work fine.
Related
The string is "Some Words(1440)" and I want to store the numbers inside the parenthesis as a variable in twig so it can be output and used. I thought maybe I could do it with a split but I wasn't able to escape the parenthesis properly.
What I have:
Some Words (1440)
What I want to extract from the string is just the numbers in parenthesis
1440
I need to extract all values, including the empty fields from the table, but the problem is that extract method skips empty fields. How can I collect those empty fields or replace them with something else?
Here is my expression for Scrapy shell:
row = response.xpath('//*[#class="apexir_WORKSHEET_DATA"]//tr//td//text()').extract()
Your xpath selector here selects text() values:
'//*[#class="apexir_WORKSHEET_DATA"]//tr//td//text()'
What you want to do is select td values and iterate over them:
items = []
rows = response.xpath('//*[#class="apexir_WORKSHEET_DATA"]//tr//td')
for row in rows:
text = ''.join(row.xpath('.//text()').extract())
items.append(text)
Now even if there is no text your code will append an empty string to your item list. Doing this with xpath alone is not possible unfortunately.
I want to create a function that extract characters from strings by using substring, but got some problems to find out the end_position to cut the character.
I got a string that stored in term of log file like that:
string = ("{\"country\":\"UNITED STATES\",\"country`_`code\":\"US\"}")
My idea is identify the position of each descriptions in the log and cut the character behind
start_position = as.numeric(str_locate(string,'\"country\":\"')[,2])
end_position = ??????
country = substring(x,start_position,end_postion)
The sign to recognize the end of character that I want to cut is the symbol "," at the end. FOR EXAMPLE: \"country\":\"UNITED STATES\",
Could you guys tell me any way to get the position of "," with condition of specific pattern in front? I intend to create a function later to extract character based on the recognized pattern. In this example, they are "country" and "country code"
Instead of using substring have a look into strsplit, that will split according to a pattern.
string = ("{\"country\":\"UNITED STATES\",\"country`_`code\":\"US\"})")
strsplit(string,",")[[1]][1]
[1] "{\"country\":\"UNITED STATES\""
You can change the pattern with every regex you like
I have a certain input string in this form: "[3] [4] at [5]"
From the following datatable, I need to replace the text on the datatable corresponding to the column index inside the bracket.
The output should be: "15A Circuit Breaker #348901836 at 19-Afalcon St. Capitol Subdivision"
Right now, I am using Regex.Replace() method but it searches for a particular pattern. My problem is the integers (corresponding the column index) enclosed inside the brackets is dynamic.
What would be the best way to achieve this?
String.Format should do it for you. Both the format string and the arguments can be easily implemented dynamically.
https://msdn.microsoft.com/en-us/library/system.string.format.aspx
All of the syntax, and a decent example of what you wish to do are on the linked page.
Anyone knows if String Aggregation in sqlite is possible?
If i have an animal column with 5 rows/datas, how can i combine them so that the output would be in one field
'dog','cat','rat','mice','mouse' as animals
Thanks
You're looking for something like the following:
select group_concat(animal) from animals;
This will return something like the following:
dog,cat,rat,mice,mouse
If you don't want to use a comma as the separator, you can add your own separator as a second parameter:
select group_concat(animal, '_') from animals;
which will return:
dog_cat_rat_mice_mouse
I think this will be useful:
group_concat(X)
group_concat(X,Y)
The group_concat() function returns a string which is the concatenation of all non-NULL values of X. If parameter Y is present then it is used as the separator between instances of X. A comma (",") is used as the separator if Y is omitted. The order of the concatenated elements is arbitrary.