ferradavi

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

11 posts in this topic

Hi there!
Is there a simple way to do this:

(assuming to select the text above)

HtItaswtdt

 

Thanks to all for your attention

Share this post


Link to post
Share on other sites



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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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)

 


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

Share this post


Link to post
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) , ""))

 


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

Share this post


Link to post
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 & '"')

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Very very cool!!

How to obtain instantly the result after selecting text? 

I mean clicking the left button mouse and releasing it in a active window.

Thanks

Edited by ferradavi

Share this post


Link to post
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

 

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Share this post


Link to post
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)

 

1 person likes this

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

Share this post


Link to post
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)

 


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

Share this post


Link to post
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