How to split json data in PowerApps
I have a json format text
{"ID":"1","name":"yashpal"}
and I need to split the data and assign 1 to textbox1 and Yashpal to textbox2
Power Apps currently does not have a general JSON parsing mechanism, but if you know that the text you have will always have the same format, and the 'name' property cannot have double quotes ("), then you can use a regular expression to extract the values, something along the lines of
With(
Match(
<<the json text>>,
"\""ID\"":\""(?<id>[^\""]+)\"",\""name\"":\""(?<name>[^\""]+)\"""),
UpdateContext({defaultId: id, defaultName: name}))
And you can use the variables defaultId and defaultName as the Default property of 'textbox1' and 'textbox2', respectively.
Sorry if question is vague.
I have a string that I want to format in a certain way
Currently it gets outputted like this
Could I output this like this?
With a new line for after each deliminator?
The common deliminator is the pipe (|) for these.
You can do this with a combination of the split() function to turn the strings into arrays of elements, and UNNEST, to convert each element in the array into a separate row:
WITH t(column, text) AS (
VALUES
('column1', 'text1|text2|text3'),
('column2', 'text3|text4|text4')
)
SELECT t.column, u.item
FROM t, UNNEST(split(t.text, '|')) u(item)
I would like to define a new style of ordered lists in asciidoctor that is composed of a fixed uppercase letter and a counter that increments. It has to be document wide. For example
A1. first item
A2. second item
some text
A3. third item
the flow of the text continues
The solution I came up with is as follows, which is heavy and not 100% satisfactory.
[horizontal]
A{counter:ol1}.:: first item
A{counter:ol1}.:: second item
some text
[horizontal]
A{counter:ol1}.:: third item
the flow of the text continues
Is there a simpler solution ? Is there a possibility at least to define a macro that would expand to A{counter:ol1}.::?
You have a couple of choices:
Create a macro in your editor that inserts the required markup (assuming that your goal is to reduce the amount of typing to achieve this effect).
Adjust the markup to specify a custom role and drop the counter:
= My document
:docinfo: shared
[horizontal, role=numbered]
A:: first item
A:: second item
some text
[horizontal, role=numbered]
A:: third item
the flow of the text continues
Then add some custom CSS, via a docinfo file (see: https://asciidoctor.org/docs/user-manual/#docinfo-file), that does the counting for you. This won't work in PDF output.
body {
counter-reset: myli;
}
.hdlist.numbered .hdlist1::after {
content: counter(myli) ". ";
counter-increment: myli;
}
Let's say I have some text in rails:
text = "A bunch of data goes in here: %#user.name%#, %#user.email%#, %#company.name%#, %#company.state%# and then some other information as well"
I am looking for the best way to parse through that text looking for all substrings between %# and another %# in order to replace it with actual data. The text should not anticipate that data will be in any particular order and it should ideally be able to turn the substrings into references to local variables that match the substring.
Use the String#scan method.
For your case in particular, the regex I used to match was: /(\%\#.*?\%\#)/
text = "A bunch of data goes in here: %#user.name%#, %#user.email%#, %#company.name%#, %#company.state%# and then some other information as well"
regex = /(\%\#.*?\%\#)/
#here's the one line version
text.scan(regex).each {|match| text.sub!(match[0], eval(match[0].gsub(/[\%\#]/, '')))}
#Here's the more organized version
text.scan(regex).each do |match|
current_match = match[0]
replacement_var = current_match.gsub(/[\%\#]/, '')
text.sub!(current_match, eval(replacement_var))
end
puts text
text = "A bunch of data goes in here: %#user.name%#, %#user.email%#, %#company.name%#, %#company.state%# and then some other information as well"
placeholder = text[/\%\#.*?\%\#/]
while placeholder
case placeholder
when "%#user.name%#"
text.sub!(/\%\#.*?\%\#/,"Steve")
when "%#user.email%#"
text.sub!(/\%\#.*?\%\#/,"steve#example.com")
when "%#company.name%#"
text.sub!(/\%\#.*?\%\#/,"Wayne Industries")
when "%#company.state%#"
text.sub!(/\%\#.*?\%\#/,"Gotham")
else
text.sub!(/\%\#.*?\%\#/,"unknown")
end
placeholder = text[/\%\#.*?\%\#/]
end
I don't know if Matlab can do this, but I want to store some strings in a 4×3 matrix, each element in the matrix is a string.
test_string_01 test_string_02 test_string_03
test_string_04 test_string_05 test_string_06
test_string_07 test_string_08 test_string_09
test_string_10 test_string_11 test_string_12
Then, I want to write this matrix into a plain text file, either comma or space delimited.
test_string_01,test_string_02,test_string_03
test_string_04,test_string_05,test_string_06
test_string_07,test_string_08,test_string_09
test_string_10,test_string_11,test_string_12
Seems like matrix data type is not capable of storing strings. I looked at cell. I tried to use dlmwrite() or csvwrite(), but both of them only accept matrices. I also tried cell2mat() first, but in that way all letters in the strings are comma seperated, like
t,e,s,t,_,s,t,r,i,n,g,_,0,1,t,e,s,t,_,s,t,r,i,n,g,_,0,2,t,e,s,t,_,s,t,r,i,n,g,_,0,3
So is there any way to achieve this?
It is possible to shorten yuk's solution a bit.
strings = {
'test_string_01','test_string_02','test_string_03'
'test_string_04','test_string_05','test_string_06'
'test_string_07','test_string_08','test_string_09'
'test_string_10','test_string_11','test_string_12'};
fid = fopen('output.txt','w');
fmtString = [repmat('%s\t',1,size(strings,2)-1),'%s\n'];
fprintf(fid,fmtString,strings{:});
fclose(fid);
Cell array is the way to store strings.
I agree it's a pain to save strings into a text file, but you can do it with this code:
strings = {
'test_string_01','test_string_02','test_string_03'
'test_string_04','test_string_05','test_string_06'
'test_string_07','test_string_08','test_string_09'
'test_string_10','test_string_11','test_string_12'};
fid = fopen('output.txt','w');
for row = 1:size(strings,1)
fprintf(fid, repmat('%s\t',1,size(strings,2)-1), strings{row,1:end-1});
fprintf(fid, '%s\n', strings{row,end});
end
fclose(fid);
Substitute \t with , to get csv file.
You can also store cell array of strings into Excel file with XLSWRITE (requires COM interface, so it's on Windows only):
xlswrite('output.xls',strings)
In most cases you can use the delimiter ' ' and get Matlab to save a string into file with dlmwrite.
For example,
output=('my_first_String');
dlmwrite('myfile.txt',output,'delimiter','')
will save a file named myfile.txt containing my_first_String.