Jump to content

SitringStripWS versus Chr(0)


Inf
 Share

Recommended Posts

Hi, All!

Writing my own "winamp song to text file" script and have problem with striping ID3v1 tags.

Got ID3.au3 form >this topic, and it works great except ID3v1 tags — it returns them full 30 bytes length.

OK, it's not a problem, stripping all trailing (and leading, if any) spaces with

$Artist=StringStripWS(_ID3GetTagField("Artist"),3)
$Track=StringStripWS(_ID3GetTagField("Title"),3)
$Album=StringStripWS(_ID3GetTagField("Album"),3)

It works, but have found 1 mp3 file with ID3v1 tags, which returns trailing Ch(0) instead of Ch(32) (spaces)

(have checked it in my generated text file viewing it in hex).

And StringStripWS doesn't strips Ch(0)  :(  (while help says "Whitespace also includes the null string ( Chr(0) ) and the standard space ( Chr(32) )").

Also checked other ID3v1-only mp3's, and they returns Ch(20), so for now the only idea I have is to ignore such *wrong* mp3's,

but I also want to know is there any solution, or did I missed something?

Edited by Inf
Link to comment
Share on other sites

Hi Inf,

  and welcome to the Forum!

Just a suggestion: Have you tried the 

$STR_STRIPALL (8) = strip all spaces (over-rides all other flags)
Constants are defined in StringConstants.au3

And try running it in BETA 

Other alternative would be Regexp...

Bill

Edited by l3ill
Link to comment
Share on other sites

  • Moderators

Inf,

StringReplace will remove the Chr(0) characters for you: :)

#include <StringConstants.au3>

$sText = "ASCII" & Chr(0) & "ASCII" & Chr(0)
ConsoleWrite(StringToBinary($sText) & @CRLF)

$sStripped = StringStripWS($sText, $STR_STRIPALL)
ConsoleWrite(StringToBinary($sStripped) & @CRLF)

$sReplaced = StringReplace($sText, Chr(0), "")
ConsoleWrite(StringToBinary($sReplaced) & @CRLF)
Jon has recently altered the way some string functions deal with Chr(0) - I will take a look back at the changes and see if they have affected this function as well. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

mikell,

That is perfectly normal as Windows regards Chr(0) as an "end-of-string" marker. :)

In another thread about Chr(0) Jon had this to say recently:

 

"Over time most of the AutoIt string functions have migrated to an internal string object that stores the length so that you can work with strings with nulls in them without too much trouble. Some APIs - like MsgBox - might not show the text correctly but as you've seen in this thread the nulls are usually preserved"

This is an entirely diffferent case where Chr(0) is not, contrary to the Help file statement, regarded as "whitespace". If Jon cannot amend the function without causing too many problems elsewhere, the short-term solution is to alter the Help file to remove Chr(0) from the list of characters removed by StringStripWS. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

I don't know anything about _ID3GetTagField but I would expect that you need to process the return in some way before using any string functions because chr(0) is used to mark the end of an ascii string, so to me, despite what the Help says, you problem is not surprising.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi,  title="SitringStripWS versus Chr(0): post #4"> Melba23 !

Did my little investigations.

Flag=8 strips ALL spaces (even single between words, while help says "To strip single spaces between words, use the function StringReplace()").

So for now i do:

$Artist=StringStripWS(  StringReplace(_ID3GetTagField("Artist"),Chr(0)," ")  ,3)
$Track=StringStripWS(  StringReplace(_ID3GetTagField("Title"),Chr(0)," ")  ,3)
$Album=StringStripWS(  StringReplace(_ID3GetTagField("Album"),Chr(0)," ") ,3)

replacing all Ch(0) with spaces (Ch(32)) and than strip leading and trailing spaces.

Thanks to all for your time, spent helping me.

Now I'm  going for ini-file and GUI :D

Link to comment
Share on other sites

I don't know anything about _ID3GetTagField but I would expect that you need to process the return in some way before using any string functions because chr(0) is used to mark the end of an ascii string, so to me, despite what the Help says, you problem is not surprising.

I'm not sure, what wrong with _ID3GetTagField, but problem in only with ID3v1, and only with some music-files.

_ID3GetTagField returns ID3v2 tags without spaces, "ready for use", ID3v1 — with.

So, only ID3v1 must be processed, and here comes problem with Ch(0).

Link to comment
Share on other sites

  • Moderators

Hi,

Jon confirms it is not an quick fix so I have opened Trac ticket #2568 for the problem.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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