How to capitalize only first letter of a sentence - powerquery

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)

Related

To combine a word in VBScript

Dim a // consider a variable as
a= Ajay Kumar Holla
and i would like to have a output as "AjayKumarHolla"
1) I would like to remove the space and join the word together.
2) the code is in VB Script and I would like to have my answer also in VBScript.
Is this what you're looking for? a = Replace(a, " ", "")

Ruby: Concise way to conditionally join strings with newlines?

I need to add a description string to an existing comments variable, which contains either a string or nil. I want to separate the new description from any existing comments with a newline, but only if there are existing comments. I've come up with a couple ways that are kind of concise,
old_comments = comments + "\n" rescue ""
new_comments = old_comments + description
or
new_comments = [comments, description].compact.join("\n")
but I'm surprised there's not a less "tricky" way to squeeze this into a one-liner. Or is there?
[*comments, description].join($/)

Ruby regex: split string with match beginning with either a newline or the start of the string?

Here's my regular expression that I have for this. I'm in Ruby, which — if I'm not mistaken — uses POSIX regular expressions.
regex = /(?:\n^)(\*[\w+ ?]+\*)\n/
Here's my goal: I want to split a string with a regex that is *delimited by asterisks*, including those asterisks. However: I only want to split by the match if it is prefaced with a newline character (\n), or it's the start of the whole string. This is the string I'm working with.
"*Friday*\nDo not *break here*\n*But break here*\nBut again, not this"
My regular expression is not splitting properly at the *Friday* match, but it is splitting at the *But break here* match (it's also throwing in a here split). My issue is somewhere in the first group, I think: (?:\n^) — I know it's wrong, and I'm not entirely sure of the correct way to write it. Can someone shed some light? Here's my complete code.
regex = /(?:\n^)(\*[\w+ ?]+\*)\n/
str = "*Friday*\nDo not *break here*\n*But break here*\nBut again, not this"
str.split(regex)
Which results in this:
>>> ["*Friday*\nDo not *break here*", "*But break here*", "But again, not this"]
I want it to be this:
>>> ["*Friday*", "Do not *break here*", "*But break here*", "But again, not this"]
Edit #1: I've updated my regex and result. (2011/10/18 16:26 CST)
Edit #2: I've updated both again. (16:32 CST)
What if you just add a '\n' to the front of each string. That simplifies the processing quite a bit:
regex = /(?:\n)(\*[\w+ ?]+\*)\n/
str = "*Friday*\nDo not *break here*\n*But break here*\nBut again, not this"
res = ("\n"+str).split(regex)
res.shift if res[0] == ""
res
=> [ "*Friday*", "Do not *break here*",
"*But break here*", "But again, not this"]
We have to watch for the initial extra match but it's not too bad. I suspect someone can shorten this a bit.
Groups 1 & 2 of the regex below :
(?:\A|\\n)(\*.*?\*)|(?:\A|\\n)(.*?)(?=\\n|\Z)
Will give you your desired output. I am no ruby expert so you will have to create the list yourself :)
Why not just split at newlines? From your example, it looks that's what you're really trying to do.
str.split("\n")

What is the best way to get 51, out of the following string

What is the best way to get '51', out of the following string in ruby :
"<https://api.example.com/users/lgs/api?page=2>; rel=\"next\", <https://api.example.com/users/lgs/api?page=51>; rel=\"last\""
Thanks in advance
Luca
If you know there're only two numbers in that string then this is enough:
str = '"<https://api.example.com/users/lgs/api?page=2>; rel=\"next\", <https://api.example.com/users/lgs/api?page=51>; rel=\"last\""'
p str.scan(/\d+/).last #=> "51"
If not then provide more detail to make the regex more precise. Also you can add to_i if you need the answer as a number.
You can use regexp in this way:
res = str.match /.page=(\d+)./
in this way you are "capturing all the digits between "(" and ")" (in the last token), and you result will be store in
res.captures.first
(or simply in $1 variable)

A good way to insert a string before a regex match in Ruby

What's a good way to do this? Seems like I could use a combination of a few different methods to achieve what I want, but there's probably a simpler method I'm overlooking. For example, the PHP function preg_replace will do this. Anything similar in Ruby?
simple example of what I'm planning to do:
orig_string = "all dogs go to heaven"
string_to_insert = "nice "
regex = /dogs/
end_result = "all nice dogs go to heaven"
It can be done using Ruby's "gsub", as per:
http://railsforphp.com/2008/01/17/regular-expressions-in-ruby/#preg_replace
orig_string = "all dogs go to heaven"
end_result = orig_string.gsub(/dogs/, 'nice \0')
result = subject.gsub(/(?=\bdogs\b)/, 'nice ')
The regex checks for each position in the string whether the entire word dogs can be matched there, and then it inserts the string nice there.
The word boundary anchors \b ensure that we don't accidentally match hotdogs etc.

Resources