Jump to content
Sign in to follow this  
langthang084

how to recognize a character at the back of the control (in word) is alphabet or number?

Recommended Posts

langthang084

i've a paragraph and I click random on it. So, how to recognize a character at the back of the control (in word) is alphabet or number?

Share this post


Link to post
Share on other sites
Melba23

langthang084,

If you are selecting characters rather then just placing the cursor in a random position within the text, then you can pass the selection to the clipboard and then use a RegEx to determine what it is:

HotKeySet("{SPACE}", "_TestChar")
HotKeySet("{ESC}", "_Exit")

While 1
    Sleep(10)
WEnd

Func _TestChar()

    ; Copy selection to the clipboard
    Send("^c")
    Sleep(100)
    ; Extract first character
    $sChar = StringLeft(ClipGet(), 1)
    ; Check if letter, digit or something else
    If StringRegExp($sChar, "[A-Za-z]") Then
        ConsoleWrite("Letter" & @CRLF)
        Return
    EndIf
    If StringRegExp($sChar, "[0-9]") Then
        ConsoleWrite("Number" & @CRLF)
        Return
    EndIf
    ConsoleWrite("Other" & @CRLF)

EndFunc


Func _Exit()
    Exit
EndFunc
All clear? :)

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
langthang084

Thanks you! M23. But how to make script stop at the end of paragraph?

Share this post


Link to post
Share on other sites
Melba23

langthang084,

First define "end of paragraph"! :D

Seriously, what exactly are you trying to do? If we know the end result we can tailor our advice rather then just throw out random ideas. ;)

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
langthang084

Ah! I want to stop at the last character (include "space"), after check character above

Share this post


Link to post
Share on other sites
Melba23

langthang084,

So you want to code to move along the text automatically? Again I ask: what is the desired end result of this script? In which app is the text you want to examine? Why are you checking the type of character? And finally, your definition of "end of paragraph" sounds like "end of word" to me. Much more detail, please. :)

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
langthang084

My paragraph like:

"Aaasasssssssaaaaaa

2222222222222

33334444

Aaaaaaaaaa

12455666....."

Total line is random but a line is only alphabet or number. So, i want to rearrange a number line be connected by the alphabet line. and finish when all line's done.

Share this post


Link to post
Share on other sites
Melba23

langthang084,

One more attempt to get some sensible answers - and if I do not get any I am out of here. :mad:

What is the purpose of all this? In what app does this "paragraph" appear? Are the lines separated by @CRLF as they are above, or something else? :huh:

Please help us to help you by giving us some more information - because at the moment what you want to do is vey unclear. ;)

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
langthang084

Hj. Sorry. The app is microsoft word. The lines are seperated by {enter}. All i want is change the layout of this paragraph

Share this post


Link to post
Share on other sites
Melba23

langthang084,

Select the paragraph, put the selected text into the ClipBoard and extract it as I showed you above. Then run StringReplace to replace CRLF with an empty string and repaste the result back into Word. :)

M23

  • Like 1

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
langthang084

Sorry, My internet was off until now.

I dont want to delete all enter. I want to connect all the number lines to the alphabet line abovet it. Like this:

"AAAAAAA

111

222

333

BBBB

444

555"

===> 

"AAAAAAA: 111,222,333

BBBB: 444,555" 

the total alphabet and number lines are random, and there're many paragraphs like this. So I want to stop the script  at "5" (End of paragraph or end of word like you understand) to run again with the new paragraph

Share this post


Link to post
Share on other sites
Malkey

Here's to M23's patience.

; Select or highlight the text to be reformated, then press "space" while this script is running..
HotKeySet("{SPACE}", "_TestChar")
HotKeySet("{ESC}", "_Exit") ; Press Esc to exit.

While 1
    Sleep(10)
WEnd

Func _TestChar()

    ; Copy selection to the clipboard
    Send("^c")
    Sleep(100)

    ; Extract characters
    Local $sText = ClipGet()

    ; Re-format text
    Local $sFormatedText = StringRegExpReplace($sText, "(?i)([a-z]+)(\v+)", "\1:")
    ;ConsoleWrite($sFormatedText & @LF & "==============" & @LF)

    $sFormatedText = StringRegExpReplace($sFormatedText, "(?m)(\d+)(\v+)", "\1,")
    ;ConsoleWrite($sFormatedText & @LF & "==============" & @LF)

    $sFormatedText = StringRegExpReplace($sFormatedText, "(?im)(\d+)(,)([a-z]+)", "\1" & @CRLF & "\3")

    ;ConsoleWrite($sFormatedText & @LF)
    ; or
    ClipPut($sFormatedText)
    Send("^v")
EndFunc   ;==>_TestChar

Func _Exit()
    Exit
EndFunc   ;==>_Exit

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
Sign in to follow this  

×