Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is there an easy way to take what I write to the write window and log it to a file? Or do I need to separately create an array of chars manually and open a file to write the char[] to? I would love to be able to write to file using regular expressions at the very least but I'm not finding much helpful info from the docs.
Looks like writeToLogEx(char format[], ...) can do what I want but it outputs to a Logging Block in the measurement setup. So I'll have some header and footer data that I don't want as well as CAN traffic if I don't put up a channel block.
Vector's Example:
char timeBuffer[64];
getLocalTimeString(timeBuffer);
writeToLogEx("===> %s",timeBuffer);
Regular Expression Options:
"%ld","%d" decimal display
"%lx","%x" hexadecimal display
"%lX","%X" hexadecimal display (upper case)
"%lu","%u" unsigned display
"%lo","%o" octal display
"%s" display a string
"%g","%lf" floating point display
"%c" display a character
"%%" display %-character
"%I64d" decimal display of a 64 bit value
"%I64x" hexadecimal display of a 64 bit value
"%I64X" hexadecimal display of a 64 bit value (upper case)
"%I64u" unsigned display of a 64 bit value
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have flowfiles with filename like that:
xxx2019xxx.txt
Where xxx are letters, I want to extract the year (2019 or whatever looks like a 4 digits numbers) within the filename. It seems to me that the Expression Language´s regex functions like matches(...) just return a boolean value. Any ideas how to extract the year?
Thank you and best regards.
You can add a dynamic property (click the + icon on the top right of the "Properties" tab of the UpdateAttribute processor). Name it "extractedYear" or whatever you like. The value of this property should be an Expression Language statement like:
${filename:replace('.*(\d{4}).*', '$1')}
That says to replace (in the new attribute, not modifying the existing filename attribute) the matched pattern (anything + 4 digits + anything) with the first capture group (aka the 4 digits).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
a= <<EOF
Password
:
7UV1ceFQ (You will be asked to change this after logging in for the first time)
EOF
I need to extract the value "7UV1ceFQ" using regular expression, I have tried using '/Password : 7UV1ceFQ/ but it's not working, I think it's because next line character is included, Can anyone please suggest me to exact this value?
▶ a[/^\S+(?=\s\(You will be)/]
#⇒ "7UV1ceFQ"
The regular expression above reads as:
starting with a new line start ^
get all non-space symbols greedy \S+
until the positive lookahead (?=\s\(You will be)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
In Ruby, I would like to create a regular expression that matches the following:
building/liberty-green/6d
(the word building and some number somewhere after it)
Currently, I have /building/ and need to add \d (any digit) to it, but I don't know how.
You need /building\/[\w-]+\/\w+/. For example:
irb(main):001:0> /building\/[\w-]+\/\w+/.match("building/liberty-green/6d")
=> #<MatchData "building/liberty-green/6d">
That expression will match any string that:
Starts with /building/
Then follows with one or more word characters or dashes (eg. foo-bar, foo, bar-1)
Then follows with a /
Finally ends with one or more word characters (eg. foo, 6d, 12345)
Note that \w includes digits.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
"\u5546\u54c1\u7f16\u53f7" is displayed as "商品编号".
"\u5546\u54c1\u7f16\u53f7" # => "商品编号"
What is the character encoding in "\u5546\u54c1\u7f16\u53f7"? How can I convert "商品编号" to "\u5546\u54c1\u7f16\u53f7"?
The \uHHHH (where HHHH is in hex) notation is simply a way to reference Unicode characters by number. This is usually used when:
You don't know how to get things like 商 out of your keyboard.
You're working in an environment that can't display all the Unicode that you need.
When you say "\u5546\u54c1\u7f16\u53f7" and see "商品编号", it simply means that you're working in a modern terminal that is Unicode aware and has a good font.
In most cases it should matter which representation you use, it all ends up as the same bytes inside the machine. However, if you must get the \u version for some reason, then you can say things like this (assuming that your encoding starts out right):
ascii_friendly = str.chars.map { |c| '\u%4.4x' % c.ord }.join
Then when you print ascii_friendly to the screen, a file, or say a JSON stream, you'll see things like
\u5546\u54c1\u7f16\u53f7
Note that the \u5546 in there is not the single Unicode 商, it is the six characters \, u, 5, 5, 4, and 6. If your target is JSON, then the \u escapes will be interpreted properly when the JSON is parsed but if your target is anything else, it will just see the six characters rather than the single Unicode character you're looking for.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
plist_values['HashData'].join("").unpack('m')[0].each_byte do |b|
hash_decoded << sprintf("%02X", b)
end
I need to translate it to other language. As I understood, it puts all contents of 'HashData' array into a string, then decodes it from Base64, But what's next?
Can you write me a step-by step explanation what it does?
Thanks in Advance!
It decodes a base64 value from plist_values (the one with key 'HashData') and converts it to printable hex.
join("") concatenates all the strings in the array (or what each element in the array returns when calling to_s).
unpack('m') from the docs decodes the string (and it assumes it is base64 encoded).
sprintf("%02X", b) from the docs returns the hexadecimal representation with upper case letters.
hash_decoded << .. appends the hex representation to the string
The bottom line is that you get a string that represents the hexadecimal version (with upper case letters) of the joined strings in plist_values['HashData'].