Jump to content

Extracting from a selected sentence only the first character of each word


Recommended Posts

  • Moderators

ferradavi,

#include <MsgBoxConstants.au3>

$sString = "Hi there! Is there a simple way to do this:"

$aRet = StringRegExp($sString, "(?:\A|\s)(.)", 3)

$sLetters = ""
For $i = 0 To UBound($aRet) - 1
    $sLetters &= $aRet[$i]
Next

MsgBox($MB_SYSTEMMODAL, "Extracted", $sLetters)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

$sStr = "Hi there!" & @LF & _
"Is there a simple way to do this:"

$aStr = stringsplit(stringreplace($sStr , @LF , " ") , " " , 2)

$output = ""

for $i = 0 to ubound($aStr) - 1
    $output &= stringleft($aStr[$i] , 1)
Next

msgbox(0 , '' , $output)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

of course Melba wins, I think locals get affinity on the server :).  His can be condensed unsafely.

#include<array.au3>

$sStr = "Hi there!" & @LF & _
"Is there a simple way to do this:"

msgbox(0, '' , _ArrayToString(StringRegExp($sStr, "(?:\A|\s)(.)", 3) , ""))

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

And another method.

#include <MsgBoxConstants.au3>

Local $sString = "Hi there!" & @LF & _
        "Is there a simple way to do this:"

$aRet = StringRegExpReplace($sString, "(?s)(?!\b\w).*?", "")

MsgBox($MB_SYSTEMMODAL, "Results", _
        'The first letter of the words in the selected text: ' & @LF & @LF & _
        '"' & $sString & '"' & @LF & @LF & _
        'are:' & @LF & @LF & _
        '"' & $aRet & '"')

 

Link to comment
Share on other sites

Hey guys,

I need your help... what's wrong about this code:

#include <Misc.au3>
#include <MsgBoxConstants.au3>

HotKeySet('{ESC}', '_Exit')
Global $hDLL = DllOpen('user32.dll')


While 1

if _IsPressed ( '1', $hDLL)   Then

        If _IsPressed('11', $hDLL) AND _IsPressed('1', $hDLL) Then 

            do
               sleep (200)

            until _IsPressed ('11', $hDLL )<>1 AND _IsPressed('1', $hDLL) <>1


_GetText()

        EndIf
     EndIf

    Sleep(200)
WEnd


Func _Exit()
    DllClose($hDLL)
    Exit
EndFunc


Func _GetText()

    Local $PrevClip = ClipGet()

    Send('^c')
    ConsoleWrite(ClipGet() & @LF)
    Local $sString=string($PrevClip)
    ClipPut($PrevClip)

$aRet = StringRegExp($sString, "(?:\A|\s)(.)", 3)

$sLetters = ""
For $i = 0 To UBound($aRet) - 1
    $sLetters &= $aRet[$i]
Next

MsgBox($MB_SYSTEMMODAL, "Extracted", $sLetters)

EndFunc

 

Link to comment
Share on other sites

#include <Misc.au3>
#include <MsgBoxConstants.au3>

HotKeySet('{ESC}', '_Exit')
Global $hDLL = DllOpen('user32.dll')

While 1

if _IsPressed ('1', $hDLL)  or  _IsPressed ('10', $hDLL) Then

        If _IsPressed('10', $hDLL) And _IsPressed('1', $hDLL) Then

            do
               sleep (200)

            until _IsPressed ('10', $hDLL )<>1 And _IsPressed('1', $hDLL) <>1

  Send('^c')

_Extract()

        EndIf
     EndIf

WEnd


Func _Exit()
    DllClose($hDLL)
    Exit
EndFunc



Func _Extract()
   Local $sData  = ClipGet()

    $sString = $sData

$aRet = StringRegExp($sString, "(?:\A|\s)(.)", 3)

$sLetters = ""
For $i = 0 To UBound($aRet) - 1
    $sLetters &= $aRet[$i]
Next

MsgBox($MB_SYSTEMMODAL, "Extracted", $sLetters)

EndFunc

... and finally I got it!

Link to comment
Share on other sites

Hi just for fun. A not regexp example.

#include <array.au3>

$sStr = "Hi there!" & @LF & _
        "Is there a simple way to do this:"


Local $aSplit = StringSplit($sStr, " " & @CRLF)
Local $sOut = ""
For $i = 1 To $aSplit[0]
    $sOut &= StringLeft($aSplit[$i], 1)
Next
ConsoleWrite($sOut & @CRLF)

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

just for fun, A not regexp nor array example.

$sStr = "Hi there!" & @LF & _
        "Is there a simple way to do this:"

$sStr = StringReplace(StringReplace(StringReplace(StringStripWS($sStr, 7), @CR, " "), @LF, " "), @TAB, " ")
Local $i = StringLen($sStr), $sOut = ""

While $i
    $i = StringInStr($sStr, " ", 0, -1, $i - 1)
    $sOut = StringMid($sStr, $i + 1, 1) & $sOut
WEnd
ConsoleWrite($sOut & @CRLF)

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

$sStr = "Hi there!" & @LF & _
        "Is there a simple way to do this:"

$sOut =  ""

while 1
    $sOut &= stringleft($sStr , 1)
    If Not StringInStr($sStr , " ") Then exitloop
    $sStr = stringtrimleft($sStr , StringinStr(StringReplace($sStr , @LF, " "), " " , 0 , 1))
wend

msgbox(0, '' , $sOut)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...