Jump to content

String To Text-String


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Developers

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 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.
  :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

image.png.9042bebbaa3e1450d0a7212eb381985c.png

I feel like I'm been thick lol? - it's one of those days!

Link to comment
Share on other sites

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

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...