mike1950r Posted June 14, 2021 Posted June 14, 2021 Hi, just have a question. Is there a function to make a string to a text string? The effect would be like: save a string to file in .txt format and load the string afterwards from this file. (then you have the string like in wordpad format) thanks for assistance. cheers mike
Luke94 Posted June 14, 2021 Posted June 14, 2021 Could you provide an example input string and the expected output please?
mike1950r Posted June 14, 2021 Author Posted June 14, 2021 Hi Luke94, thanks for your answer. The input-string is any non wordpad-compatible string, just a copy clip of a html page for example, or a copy clip of word ... The output-string is just txt format (wordpad-compatible). I get this result with the following function: Func TextString($sString) Local $hFileOpen, $sFilePath, $sFileRead If StringLen($sString) > 0 Then $sFilePath = _TempFile() $hFileOpen = FileOpen($sFilePath, $FO_ANSI + $FO_OVERWRITE + $FO_CREATEPATH) FileWrite($hFileOpen, $sString) FileClose($hFileOpen) $hFileOpen = FileOpen($sFilePath, $FO_READ) $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) FileDelete($sFilePath) Return $sFileRead EndIf EndFunc ;==>TextString Hope this helps to understand. Cheers mike
Developers Jos Posted June 14, 2021 Developers Posted June 14, 2021 (edited) Mike, An example would really help as your explanation is stil pretty much open for interpretation. So provide a code snipped that does show your challenge ( preferably in a codebox -> post code) ! Jos Edited June 14, 2021 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
mike1950r Posted June 14, 2021 Author Posted June 14, 2021 Func TextString($sString) Local $hFileOpen, $sFilePath, $sFileRead If StringLen($sString) > 0 Then $sFilePath = _TempFile() $hFileOpen = FileOpen($sFilePath, $FO_ANSI + $FO_OVERWRITE + $FO_CREATEPATH) FileWrite($hFileOpen, $sString) FileClose($hFileOpen) $hFileOpen = FileOpen($sFilePath, $FO_READ) $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) FileDelete($sFilePath) Return $sFileRead EndIf EndFunc ;==>TextString Hi Jos, thanks for your answer. I go to a browser or word or whatever mark a selection click ctrl + c Now: Local $sString = Clipget() $sString = TextString($sString) $sString contents now the clip in notepad format, say only text. Hope i could make things clearer. cheers mike
Luke94 Posted June 14, 2021 Posted June 14, 2021 10 minutes ago, mike1950r said: Func TextString($sString) Local $hFileOpen, $sFilePath, $sFileRead If StringLen($sString) > 0 Then $sFilePath = _TempFile() $hFileOpen = FileOpen($sFilePath, $FO_ANSI + $FO_OVERWRITE + $FO_CREATEPATH) FileWrite($hFileOpen, $sString) FileClose($hFileOpen) $hFileOpen = FileOpen($sFilePath, $FO_READ) $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) FileDelete($sFilePath) Return $sFileRead EndIf EndFunc ;==>TextString Hi Jos, thanks for your answer. I go to a browser or word or whatever mark a selection click ctrl + c Now: Local $sString = Clipget() $sString = TextString($sString) $sString contents now the clip in notepad format, say only text. Hope i could make things clearer. cheers mike If I copy the entire AutoIt Homepage and use the following code: #include <MsgBoxConstants.au3> Global $sString = ClipGet() MsgBox($MB_SYSTEMMODAL, 'ClipGet', $sString) I get the following output: Quote AutoIt FORUM WIKI AUTOIT AUTOIT EDITOR SOFTWARE CODE BLOG CONTACT US SEARCH … AutoIt Script Editor We looked at many editors to see which one was the most useful editor for AutoIt. We found SciTE and saw its potential and wrote a customized Lexer for the Syntax Highlighting and Syntax folding and created a special installer called SciTE4AutoIt3. Read More... 12 ForumWikiAutoItAutoIt EditorSoftwareCodeBlogContact Us Copyright ©2021 AutoIt Consulting Ltd Privacy - Cookies - Ts&Cs What's wrong with that? I can paste it into Notepad/WordPad just fine. What are you wanting to be removed - everything except alphanumeric characters?
Luke94 Posted June 14, 2021 Posted June 14, 2021 (edited) Are you wanting to replace the copied text in the Clipboard with the "formatted" text? If so, that can be done with ClipPut. Local $sString = Clipget() $sString = TextString($sString) $sString contents now the clip in notepad format, say only text. ClipPut($sString) Edited June 14, 2021 by Luke94 Bad wording
mike1950r Posted June 14, 2021 Author Posted June 14, 2021 Hi Luke94, I think you misunderstood me. My Function above works fine and i can get the notepad formated text with that. I just was asking if Autoit includes already a function for doing this. Also if you copy (like your example) something from the autoit site into an richedit control, it's NOT the same copying it into notepad. In richedit control you will get all additional formats in the string like url, colour, fontsize, fonttype etc. in notepad you will get only the text in standard format, nothing else. Hope you understand, what i mean. cheers mike
Luke94 Posted June 14, 2021 Posted June 14, 2021 The formatting should be removed from this one line anyway? Global $sString = ClipGet() I'm sure the formatting is stored within the Clipboard, so once you call: ClipPut($sString) The string is passed to the Clipboard as plain text, without formatting. This means your TextString function, as well as the built-in function you're looking for is pointless. The two above lines will do what you need. I tried with the the two above lines and this was the output. I feel like I'm been thick lol? - it's one of those days! mike1950r 1
mike1950r Posted June 14, 2021 Author Posted June 14, 2021 Luke94, thanks lot. I didn't know that ClipPut() changes the format to $CF_TEXT format. The problem was, that i wanted to paste into richedit only in text format. I have modified my function for pasting "cleaning" the clipboard before with ClipGet() and ClipPut(). Works now like charming. Func WindowEditPaste() Local $sClip $sClip = ClipGet() If StringLen($sClip) > 0 Then ClipPut($sClip) _GUICtrlRichEdit_Paste($hGlo_WE_Control) _GUICtrlRichEdit_SetModified($hGlo_WE_Control, True) EndIf EndFunc ;==>WindowEditPaste Many thanks again. Sometimes it's easier than thought. Cheers mike
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now