José Perez
asked on
Extract all first characters of any word in a text
Hi,
I have to write a programm that given a text (in a textbox), when runing, the result in another textbox is the first letter of every word the original text has in it. Ideally, the result shoud be in UPPER case and should have all points the original text have.
Example:
Textbox1.Text= "Our Father in heaven, hallowed be your name.
Your kingdom come, your will be done, on earth, as it is in heaven.
Give us this day our daily bread, and forgive us our debts, as we also have forgiven our debtors.
And lead us not into temptation, but deliver us from evil."
Result in Textbox2.Text should be the following:
"OFIHHBYN.GUTDODBAFUODAWAH FOD.ALUNIT BDUFE"
I was thinking to use the Substring(0,1) function.
I have to write a programm that given a text (in a textbox), when runing, the result in another textbox is the first letter of every word the original text has in it. Ideally, the result shoud be in UPPER case and should have all points the original text have.
Example:
Textbox1.Text= "Our Father in heaven, hallowed be your name.
Your kingdom come, your will be done, on earth, as it is in heaven.
Give us this day our daily bread, and forgive us our debts, as we also have forgiven our debtors.
And lead us not into temptation, but deliver us from evil."
Result in Textbox2.Text should be the following:
"OFIHHBYN.GUTDODBAFUODAWAH
I was thinking to use the Substring(0,1) function.
HI,
You could first clean the string to have only points as punctuation and then use split
http://msdn.microsoft.com/de-de/library/tabh47cf(v=vs.110).aspx
and create a str looping your array with Substring(0,1)
Regards
You could first clean the string to have only points as punctuation and then use split
http://msdn.microsoft.com/de-de/library/tabh47cf(v=vs.110).aspx
and create a str looping your array with Substring(0,1)
Regards
The results in your example is also including sentence punctuation. Is that also a requirement of your program?
The simplest means to do what you are looking for is to use the string.Split function and loop through the resulting array. If you need to include punctuation, you would split on the sentence terminator (period, question mark, exclamation mark) and then split on the space for each sentence in the array.
The simplest means to do what you are looking for is to use the string.Split function and loop through the resulting array. If you need to include punctuation, you would split on the sentence terminator (period, question mark, exclamation mark) and then split on the space for each sentence in the array.
ASKER
Carl Tawn:
Think we're almost done... I have coded the following, and put the result in a Messagebox and it is displaying each word as I desired, but now I have to write it to the Textbox2... can you tell how to put all together in just 1 string?
Think we're almost done... I have coded the following, and put the result in a Messagebox and it is displaying each word as I desired, but now I have to write it to the Textbox2... can you tell how to put all together in just 1 string?
Public Class LetraXpalabra
Private Sub btnAnalizar_Click(sender As Object, e As EventArgs) Handles btnAnalizar.Click
Dim texto As String = txtTextoOriginal.Text 'original text
Dim b As String() = texto.Split(" ".ToCharArray)
'Dim a As String = a
For Each palabra In b
MessageBox.Show(palabra.Substring(0, 1))
Next
End Sub
End Class
Change your For to:
Dim sb As New StringBuilder()
For Each palabra In b
sb.Append(palabra.Substring(0, 1))
Next
txtOutput.Text = sb.ToString()
ASKER
vb.net does not recognize "StringBuilder" should I have to import some library?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Good luck in deciphering the old lady prayer cards (that is what you are doing, isn't it?).
I read about that and it is both a fascinating and moving story.
I read about that and it is both a fascinating and moving story.
ASKER
With this code it is done! and yes it is a fascinating story!
Thanks for your comment.
God bless you!
Thanks for your comment.
God bless you!
You could also do it with a Linq query, but that would depend on which version of .Net you are using.