This question already has answers here:
Search a string in VBScript to verify if contains a character
(2 answers)
Closed 2 years ago.
I'm slightly confused. I've written a small piece of a code that reads a string and outputs if the word is present in the string. The below code returns me 1 as expected
Sub FindSomeText()
MsgBox InStr("Look in this string", "Look")
End Sub
When i used the same logic on the below code but with a longer string i get a response of 16? instead of 1. Why would this be?
Sub SearchAString()
MsgBox InStr("Search through this random string and find how many strings are similar", "this")
End Sub
You are looking for the string this. In the string Search through this ..., the term this starts on the 16th position. There is no issue with the way you use it.
Instr returns the position of the searched term and not a boolean saying if the term is present or not.
If the searched term is not found, Instr will return 0
Related
This question already has answers here:
How do I break a string in YAML over multiple lines?
(9 answers)
Closed 4 years ago.
I have an entry in my yaml file that looks like this
my_key:['short string', 'thisisaverylongstringthatcontains.,specialcharacterssoI havetousequotes,andI wanttobreakintomultiplelines']
My very long string can't contain spaces, and I am worried if I simply use newline, it will get converted to space.
What is the cleanest, simplest way to break down that second string across multiple lines for easier readability and convenience?
key : ['short string', "this is a very long string
that I want to break into
multiple lines"]
Have you tried just inserting a newline? This is valid YAML.
If you don't want spaces, add \ to the end of each line.
key : ['short string', "this is a very long string\
that I want to break into\
multiple lines"]
I have a long string/text, e.g.
...blahblahblahblah,"shortcode":"Bk5z5Lgn1234",blahblahblablha...,"shortcode":"Wuipsz5Lgn1234",blahblahblablh...
I'm looking to extract all substrings of the following pattern:
"shortcode":"Bk5z5Lgn1234"
"shortcode":"Wuipsz5Lgn1234"
The values of the shortcodes, i.e. Bk5z5Lgn1234 and Wuipsz5Lgn1234, are of constant length (11 characters). Just getting the values will be fine. If getting all the occurrences of shortcode values is complicated, just getting the first value will be sufficient.
I know how to find the substrings (using the scan method), but I have no idea how to traverse the string and pull out the shortcode values.
If the code is always in the exact format that you specified, and 11 characters long, this regular expression will find them:
"shortcode":"(.{11})"
The following will return all the matches:
text.scan(/"shortcode":"(.{11})"/)
This is admittedly likely not to be the most efficient solution, but simple and easy to use. Parsing HTML with regular expressions is never the best idea.
This question already has answers here:
Breaking up long strings on multiple lines in Ruby without stripping newlines
(8 answers)
Closed 6 years ago.
I apologise I am sure the answer is out there but I simply cannot articulate it well enough for google search..
Given a long piece of code
puts 'This is a really long line of ruby code here'
How can you separate it over 2 lines, i.e.
puts 'This is a really long
line of ruby code here'
str = 'first line'\
' second line'\
' third line'
puts str
A similar question was asked a few years ago, but the accepted answer is vague at best and confusing at worst.
I'm attempting to pass a number that I've retrieved via Regex from a fetched page as the source of a filter.
Here's the link to my pipe: http://pipes.yahoo.com/pipes/pipe.info?_id=4c087880efe5ef2ea62261ff9e7eee1b
I need to get the emitted value from the loop (which is currently 555) and pass that to the string builder so that it prepends a #; I will then pass that built string as the source for my greater than filter on the item.title of the fetched RSS feed.
Since the loop module outputs an array, I currently can't find a way to connect it to the string builder module.
Within for loop we can either get one String from list of String or we can use split("") method to divide String into words
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Perfect way to write a gsub for a regex match?
I am trying to write a gsub for a regex match, but I imagine there's a more perfect way to do this .
My equation :
ref.gsub(ref.match(/settings(.*)/)[1], '')
So that I can take this settings/animals, and return just settings.
But what if settings is null? Than my [1] fails as expected.
So how can one write the above statement assuming that sometimes settings won't match ?
Use /(settings|)(.*)/, then first group will return you "settings" or empty string, if it is not present.
puts 'settings/123'.match(/(settings|)(.*)/)[1];
puts 'Xettings/123'.match(/(settings|)(.*)/)[1];