Re: Remove new line char

Liste des GroupesRevenir à cl tcl 
Sujet : Re: Remove new line char
De : mssr953 (at) *nospam* gmail.com (Michael Soyka)
Groupes : comp.lang.tcl
Date : 20. Mar 2025, 16:12:08
Autres entêtes
Organisation : self
Message-ID : <vrhb88$3eoll$1@dont-email.me>
References : 1 2 3 4 5 6
User-Agent : Mozilla Thunderbird
On 03/20/2025 5:34 AM, alexandru wrote:
Here is the code.
Can anywone test on Windows with Excel?
The test procedure is:
 Open an Excel table with data an copy one single cell.
In the Tcl/Tk console execute the code below.
See how the copied text is output to the window.
In my case there is an additional line under the copied text, meaning a
new line was still created.
  package require twapi
proc ::ClipboardGetText {} {
  ::twapi::open_clipboard
  set text [::twapi::read_clipboard 1]
  ::twapi::close_clipboard
  return $text
}
proc ::ClipboardSetText {text} {
  # Write clipboard content
  ::twapi::open_clipboard
  ::twapi::empty_clipboard
  ::twapi::write_clipboard_text $text
  ::twapi::close_clipboard
}
 ## Remove line breaks at the end of string (mostly to avoid issues when
copying from Excel)
proc ::test {} {
  set text [::ClipboardGetText]
  puts [format %x [scan [string index $text end] %c]]
  set text [regsub {[\r\n]+$} $text ""]
  set text [regsub {[[:space:]]+$} $text ""]
  set text [regsub {[\s]+$} $text ""]
  set text [regsub {\x0$} $text ""]
  # Do not use "trim" since we want to preserve trailing white spaces
but remove new line char
  puts $text
}
::test
--
I'm running Windows 10 with tcl 9 in the USA.  Following your suggestion above and using your code, I did this:
     set text [::ClipboardGetText]
     foreach c [split $text {}] {puts [scan c $c]}
and I get the desired text plus 3 trailing characters: \r\n\x00.
So, would this regular expression: {\r\n\x00} do what you want?
-mike

Date Sujet#  Auteur
19 Mar 25 * Remove new line char23alexandru
19 Mar 25 +* Re: Remove new line char4Ralf Fassel
19 Mar 25 i`* Re: Remove new line char3alexandru
19 Mar 25 i `* Re: Remove new line char2Michael Soyka
20 Mar 25 i  `- Re: Remove new line char1alexandru
19 Mar 25 +- Re: Remove new line char1Arjen
19 Mar 25 +* Re: Remove new line char16Harald Oehlmann
19 Mar 25 i`* Re: Remove new line char15alexandru
19 Mar 25 i +- Re: Remove new line char1alexandru
19 Mar 25 i `* Re: Remove new line char13Rich
20 Mar 25 i  `* Re: Remove new line char12alexandru
20 Mar 25 i   `* Re: Remove new line char11alexandru
20 Mar 25 i    +* Re: Remove new line char9Harald Oehlmann
20 Mar 25 i    i`* Re: Remove new line char8alexandru
20 Mar 25 i    i `* Re: Remove new line char7Rich
21 Mar 25 i    i  `* Re: Remove new line char6Harald Oehlmann
21 Mar 25 i    i   `* Re: Remove new line char5Rich
21 Mar 25 i    i    +* Re: Remove new line char3alexandru
23 Mar 25 i    i    i`* Re: Remove new line char2Harald Oehlmann
24 Mar 25 i    i    i `- Re: Remove new line char1Ashok
23 Mar 25 i    i    `- Re: Remove new line char1Harald Oehlmann
20 Mar 25 i    `- Re: Remove new line char1Michael Soyka
20 Mar 25 `- Re: Remove new line char1Simon Geard

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal