Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

HTML 2 ASCII ...


  • Please log in to reply
2 replies to this topic
BoBo
  • Guests
  • Last active:
  • Joined: --
It seems not possible to get ASCII from HTML using AHK's transform command while ASCII to HTML is possible :cry:

Therefore I had a try with a workaround.
Feel free to tweak it :wink:

#SingleInstance
SetBatchLines, -1

Loop, Read, My.html, MyConverted.txt
	{
	Line = %A_LoopReadLine%
	If Line =												    ; Skip empty line
		Continue
	Loop
		{
		IfInString, Line, &#								  ; Section to convert identified HTML chars
			{
			StringGetPos, Pos, Line, &#					 ; Get position of the HTML char
			Pos += 3
			StringMid, Val, Line, %Pos%, 4
			StringGetPos, ValLen, Val, `;
			StringMid, Val, Val, 1, %ValLen%				    ; Extract its value
			Transform, ASCII, Chr, %Val%					     ; Convert/transform its value to an ASCII char
			StringReplace, Line, Line, &#%Val%`;, %ASCII%	; Replace the HTML char with its ASCII char
			}
		Else
			{
			Break											   ; Nothing to convert/transform, keep original line
			}
		}
	FileAppend, %Line%`n									; Write the converted line to the outputfile
	}
ExitApp

8)

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Nice script. By the way, the transform command doesn't go in the opposite direction because converting from HTML to text (reliably) would probably involve a lot of code unless there's some function built into the OS for that. This is due to all the various tags and syntax that might be present.

However, if you copy HTML onto the clipboard -- such as by copying and pasting from an open browser window -- it will be automatically converted to plain text when you refer to the clipboard variable.

BoBo
  • Guests
  • Last active:
  • Joined: --
The mission I've accomplished :)

I took a line from a file

/61/46/A0194600,Alfvén, Hannes Olof Gösta


Downloaded the file from its destination (link) and named it using the kept filename

http://www.barley.com/61/46/A0194600.wav -> Alfvén, Hannes Olof Gösta.wav

Following your advise that'll work to convert (é=ASCII 233 and ö= ASCII 246) as well :?:

ClipBoard = %filename%
URLDownloadToFile, www.barley.com%[color=red]link[/color]%.wav, [color=blue]%ClipBoard%[/color].wav

8)