How to remove numbers from a string [closed] - ruby

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 "

Related

Laravel How to filter inputs before going to the DataBase? [closed]

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.

Remove string from each item on array using VB [closed]

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

Adding a '-' sign before any phone number based on a condition [closed]

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

how to remove '\' from string [closed]

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
I am new to ruby.I have a string like
string = "You have successfully placed Service Request No. \#{#service_requests.id} for \#{#service_requests.category.name} . Our representative will be in touch with you soon for the same. Thank you."
and I want to remove "\" from whole string.
output_string = "You have successfully placed Service Request No. #{#service_requests.id} for #{#service_requests.category.name} . Our representative will be in touch with you soon for the same. Thank you."
How to make it possible.
>> string = "You have successfully placed Service Request No. \#{#service_requests.id} for \#{#service_requests.category.name} . Our representative will be in touch with you soon for
the same. Thank you."
>> puts(string)
=> You have successfully placed Service Request No. #{#service_requests.id} for #{#service_requests.category.name} . Our representative will be in touch with you soon for the same. Thank you.
>> puts(string.inspect)
=> "You have successfully placed Service Request No. \#{#service_requests.id} for \#{#service_requests.category.name} . Our representative will be in touch with you soon for the same. Thank you."
Make sure you know what the difference between string representation (puts string.inspect) and string content (puts string) is, and note the backslashes as the artifacts of the representation.
Try this:
string.gsub(/\\/, '') # or string.gsub!(/\\/, '') for inplace substitution
You can remove this like:
string.gsub(%r{\"}, '')

generate a master key as short as possible [closed]

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?

Resources