I have a list of all 5 digit combinations possible and I also have a sentence in which I would like to add each number. Here's an example:
List items:
11111, 22222, 33333.. etc
Sentence:
Hello userXXXXX, how are you?
Desired result:
Hello user11111, how are you?
Hello user22222, how are you?
Hello user33333, how are you?
The list of numbers is huge and the sentence keeps changing. I need a way to do this automatically.
Is such a thing possible?
Place the list in column A. Place this template sentence in cell B1:
Hello user XXXXX, how are you?
In C1 enter:
=LEFT($B$1,FIND("XXXXX",$B$1)-1) & INDEX(A:A,ROWS($1:1)) & MID($B$1,FIND("XXXXX",$B$1)+5,9999)
and copy down:
Maybe (Excel), copied across and down to suit:
=SUBSTITUTE(B$1,"XXXXX",$A2)
Related
I want randomly to select a word from a cell that is generated by a form field using the "paragraph" answer option.
In one formula:
=index(split(A1," "),randbetween(1,1+len(A1)-len(substitute(A1," ",""))))
Does not remove punctuation.
Anchor the 1s in A1s (ie > A$1s) and can be copied down to suit (for different choices from the same cell).
Let's say you want to get a random word from a string in cell A1:
Get word count:
A2 =if(A1="","",counta(split(A1," ")))
Get random value between 1 and word count:
A3 =randbetween(1,A2)
Get the random word using the random value:
A4 =index(split(A1, " "),A3)
I know of the m function Text.Proper which capitalizes all words in a sentence. However, I want to know how I can capitalize only the first word of a sentence?
Something along the lines of the following. You didn't specify any details
= Table.AddColumn(Source, "Converted", each Text.Upper(Text.Middle([Column1],0,1))&Text.Middle([Column1],1,Text.Length([Column1])))
Try this, Excel style ;-)
let
Input = "text to capitalize",
Output = Text.Upper(Text.Start(Input,1)) & Text.End(Input,Text.Length(Input)-1)
in
Output
There are a couple of decent answers already, but here's another option that demonstrates a couple more functions:
Text.Upper(Text.At([Text],0)) & Text.Range([Text], 1, Text.Length([Text]) - 1)
I have a series of strings that all include 1 or many numbers (a number in this case would be 123,123,123) in the following format
"This is a number 123,124,123"
"These are some more numbers 123,345,123; 231,123,123; 124,152,123"
"This one is an odd situation 123,124,125; 123,123,123; more text"
What is the cleanest way to parse these numbers into either an array or a string that I can split that looks like this?
"123,124,123"
"123,345,123;231,123,123;124,152,123"
"123,124,125;123,123,123;"
Ultimately I want to be able to separate out the numbers like this.
"123,124,123"
"123,345,123" "231,123,123" "124,152,123"
"123,124,125" "123,123,123"
Currently attempting to use
"string".scan( /\d/ )
but obviously this is only giving me the numbers without the commas and also not separated properly.
Do it like this
string.scan(/[\d,]+/)
Another way would be to remove the unwanted characters.
arr = ["This is a number 123,124,123",
"These are some more numbers 123,345,123; 231,123,123; 124,152,123",
"This one is an odd situation 123,124,125; 123,123,123; more text"]
arr.map { |str| str.gsub(/[^\s\d,]+/,'').split }
#=> [["123,124,123"],
# ["123,345,123", "231,123,123", "124,152,123"],
# ["123,124,125", "123,123,123"]]
Regex that matches your numbers is \d{1,3}(,\d{3})*
My problem is I have a very large file, an example:
f = %q(1:9- The cost of\n
51:10- The beams cost so much\n
41:11- Should we buy more beams\n
21:12- Why buy more}
What I need to do is, as an example, is extract every beams word from any line that contains that particular word. But each beams word must come with the reference for the line it comes from, like this:
51:10 beams\n
41:11 beams\n
Any help is gratefully appreciated.
/(\d{2,2}:\d{2,2})-.*?(beams)/
The first capture will contain the line reference and the second the word beams
You can extract using scan:
f.scan(/^(\d+\:\d+).+?(beams)/)
=> [["51:10", "beams"], ["41:11", "beams"]]
And for the output:
f.scan(/^(\d+\:\d+).+?(beams)/).each do |pair|
puts pair.join(" ")
end
=>
51:10 beams
41:11 beams
Our application is mining names from people using Twitter to login.
Twitter is providing full names in a single string.
Examples
1. "Froederick Frankenstien"
2. "Ludwig Van Beethoven"
3. "Anne Frank"
I'd like to split the string into only two vars (first and last) based on the first " " (space) found.
Example First Name Last Name
1 Froederick Frankenstein
2 Ludwig Van Beethoven
3 Anne Frank
I'm familiar with String#split but I'm not sure how to only split once. The most Ruby-Way™ (elegant) answer will be accepted.
String#split takes a second argument, the limit.
str.split(' ', 2)
should do the trick.
"Ludwig Van Beethoven".split(' ', 2)
The second parameter limits the number you want to split it into.
You can also do:
"Ludwig Van Beethoven".partition(" ")
The second argument of .split() specifies how many splits to do:
'one two three four five'.split(' ', 2)
And the output:
>> ruby -e "print 'one two three four five'.split(' ', 2)"
>> ["one", "two three four five"]
Alternative:
first= s.match(" ").pre_match
rest = s.match(" ").post_match