Solved

Extract all first characters of any word in a text

Posted on 2014-01-24
9
339 Views
Last Modified: 2014-01-24
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.GUTDODBAFUODAWAHFOD.ALUNITBDUFE"

I was thinking to use the Substring(0,1) function.
0
Comment
Question by:José Perez
9 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
That would work. Simply split the string on the space character, to get an array, loop through and use Substring(0,1) to grab the first character from each word.

You could also do it with a Linq query, but that would depend on which version of .Net you are using.
0
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
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
0
 
LVL 25

Expert Comment

by:Shaun Kline
Comment Utility
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.
0
 
LVL 2

Author Comment

by:José Perez
Comment Utility
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?

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

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
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()

Open in new window

0
 
LVL 2

Author Comment

by:José Perez
Comment Utility
vb.net does not recognize "StringBuilder" should I have to import some library?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 200 total points
Comment Utility
It's in the System.Text namespace, so you might need to either add an Import directive at the top of your page:
Imports System.Text

Open in new window

Or, use the fully qualified name:
Dim sb As New System.Text.StringBuilder()

Open in new window

0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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.
0
 
LVL 2

Author Comment

by:José Perez
Comment Utility
With this code it is done! and yes it is a fascinating story!
Thanks for your comment.
God bless you!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now