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
this is an interview question:
Say if we have a lock, the lock has a 4-digits password, the password only contains numbers 0-9. For example, the password is 1234.
In order to open the lock, we can enter a string of numbers. This string can be very long and if the string contains the password, we say this string is a valid key to open the lock.
For example, if the lock has a password of 1234, we enter 176461234, 176461234 is a valid key because the last four digits is 1234 and 176461234 is also a valid key for 1764, 7646, .... 000881234 is also valid for 1234, but 78123 is not.
How to generate a string master key as short as possible to solve all passwords from 0000 to 9999?
Related
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 5 months ago.
Improve this question
Laravel How to filter inputs before going to the DataBase
what shoud i do to filter my inputs before saving to the database? i want it to be uniformed in like this format "Name" a uper case followed by lowercase.
in some cases like when the user register a full caps name i want it to be re format as the example "Name"
there's an especific PHP function to do what you need: ucfirst(). This function turns to Uppercase the first char from a string.
For example:
//If $request->name is 'JoHn' or whatever
$filtered_name = ucfirst($request->name);
//Returns 'John'
If is a case with two names, you can use the ucwords() PHP function (Turn first letter uppercase of every word from a string)
//If $request->name is 'OlivER JAMES'
$filtered_name = ucwords($request->name);
//Returns 'Oliver James'
Hope this help you.
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 last year.
This post was edited and submitted for review last year and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
Basically I've an array that looks like this
array = ("Hello_123","Hello_234","Hello_345")
I would like to remove the word "Hello_" from the array so that the result would become
array = ("123","234","345")
Any idea how can I do that please?
As stated by #user692942, loop through the array and update the values using Replace() like this:
MyArray = Array("Hello_123","Hello_234","Hello_345")
For i = 0 to UBound(MyArray)
MyArray(i) = Replace(MyArray(i),"Hello_","")
Next
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 4 years ago.
Improve this question
I need to add a - sign before any phone number ending with } and remove that }
For example, consider this sample file:
*My phone number is 9999999999}<br>
Ram is calling to 88888888}<br>
653426} Rohan is trying to call 777777777*
Expected output:
*My phone number is -9999999999<br>
Ram is calling to -88888888<br>
-653426 Rohan is trying to call 777777777*
This will do the trick:
sed -i 's/\s\([0-9]*\)\}/ -\1/g' vv.txt
Description:
vv.txt is the file from the sample provided by you
\s\([0-9]*\)\} : will capture everything that is enclosed in a space and is a digit upto }
-\1/g : here we are replacing everything we captured in between space \s and symbol } in the previous step, with a negative sign
the output on the sample file is:
*My phone number is -9999999999<br>
Ram is calling to -88888888<br>
Rohan is trying to call 777777777*
To take care of the additional condition mentioned in comments you can do two things:
1.
sed -i 's/\([0-9]*\)\}/ -\1/g' vv.txt
but this will add a space in front of - if the line begins with the number as you said.
Alternatively if you don't want the space.
2.
sed -i 's/\s\([0-9]*\)\}/ -\1/g;s/^\([0-9]*\)\}/-\1/g' vv.txt
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 6 years ago.
Improve this question
I am developing a Linux device driver where I have to pass a string of characters to it using sysfs interface. Can the sysfs attributes accept the data in a string form (something like echo "somedata" > sysfs_interface )?
I have implemented it above, and it seems to be working fine, but I would like to make certain that this is valid (acceptable in the kernel community).
Can the sysfs attributes accepts the data in a string form ...
Yes.
Actually that is what sysfs accepts when you use echo. When you use echo 0 the output is two bytes, 0x30 (the ASCII code for digit zero) and 0x0A (a newline).
For example the GPIO LED interface uses keywords to report and select the trigger.
# cat /sys/class/leds/d8/trigger
none nand-disk mmc0 timer [heartbeat] gpio
(The bracketed keyword indicates the current selection, the heartbeat timer.)
# echo none > /sys/class/leds/d8/trigger
# cat /sys/class/leds/d8/trigger
[none] nand-disk mmc0 timer heartbeat gpio
... (something like echo "somedata" > sysfs_interface )
You don't even need to use the quote marks.
See the above example of setting the LED trigger to none.
ADDENDUM
these are the custom interfaces ...
No, this is in mainline .
... but what about the one provided by the subsystem?
The authoritative answer is from Linux Documentation/filesystems/sysfs.txt:
Attributes should be ASCII text files, preferably with only one value
per file.
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
I want the following:
"Set off to London 29min"
to become:
"Set off to London min"
I also want to remove the "min" and space as well, but I know how to do it in a very inefficient way.
This will do:
string.tr("0-9", "")
If I understand you correctly then here are some solutions.
string = "Set off to London 29min"
string.gsub!(/\d+/,"")
#=> "Set off to London min"
or if you would also like the literal word 'min' taken out as well
string = "Set off to London 29min"
string.gsub!(/(\d+|(min))/,"")
#=> "Set off to London "