String with character "

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Johell
Posts: 12
Joined: 17 Apr 2021, 05:39

String with character "

18 Apr 2021, 20:36

I need to create an email and I am using this code:

Code: Select all

MailItem.Subject: = clipboard "-> code:"
Unfortunately, when inside the clipboard there are quotes, the string "-> Code:" is not printed.

For example when the clipboard contains this text:

Code: Select all

Sample text "in quotation marks" and "still quotation marks"
I have the error mentioned above, how can I fix it?
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: String with character "

18 Apr 2021, 22:36

You have a space between the : and =:

Code: Select all

MailItem.Subject: = clipboard "-> code:"
Change to:

Code: Select all

MailItem.Subject := clipboard "-> code:"
Johell
Posts: 12
Joined: 17 Apr 2021, 05:39

Re: String with character "

18 Apr 2021, 22:39

there is no space between : and = was just a typo, my code is this:

Code: Select all

MailItem.Subject := clipboard " - Code: "
yet the error still presents itself
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: String with character "

18 Apr 2021, 23:13

So I guess you’re saying the following test code shows what you want in the MsgBox correctly, but that’s not how it gets loaded in the subject line of the email. Is that correct?

Code: Select all

Clipboard = Sample text "in quotation marks" and "still quotation marks"
Subject := clipboard "-> code:"
MsgBox % Subject
Johell
Posts: 12
Joined: 17 Apr 2021, 05:39

Re: String with character "

20 Apr 2021, 08:12

Exactly, from the msgbox it appears as it should appear, while on the subject of the mail, the final part is missing, that is: "-> Code:"
Why? Is it possible to solve?
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: String with character "

20 Apr 2021, 08:51

I can't reproduce the problem. This Outlook email:

email.png
email.png (5.76 KiB) Viewed 291 times

...was produced with this code:

Code: Select all

Clipboard = Sample text "in quotation marks" and "still quotation marks"
MailItem := ComObjActive("Outlook.Application").CreateItem(0)
MailItem.Subject := Clipboard "-> code:"
MailItem.Display
Johell
Posts: 12
Joined: 17 Apr 2021, 05:39

Re: String with character "

20 Apr 2021, 10:16

I found that the problem stems from the source I copy the string from: a pdf file.
Obviously, some annoying characters are generated in the copy. Is there a function that cleans the string while keeping only standard text characters?
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: String with character "

20 Apr 2021, 10:30

I don't know of an existing one, but this does that:

Code: Select all

MsgBox, % CleanString("here is some text with some unwanted™¤µ characters ")
return

CleanString(str) {
	loop, % StrLen(str)
		if ((c := Ord(SubStr(str, A_Index, 1))) >= 32) && (c <= 126)
			clean .= Chr(c)
	return clean
}
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: String with character "

20 Apr 2021, 10:43

Or this may be faster/better:

Code: Select all

CleanString(str) {
	return RegExReplace(str, "[^[:ascii:]]")
}
Johell
Posts: 12
Joined: 17 Apr 2021, 05:39

Re: String with character "

20 Apr 2021, 10:44

Thanks a lot it works :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Rohwedder and 434 guests