WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Mehrzeiligen Text als String einfügen

 

Jan S
Moderator

Moderator


Beiträge: 11.057
Anmeldedatum: 08.07.10
Wohnort: Heidelberg
Version: 2009a, 2016b
     Beitrag Verfasst am: 15.12.2011, 10:57     Titel: Mehrzeiligen Text als String einfügen
  Antworten mit Zitat      
Hallo,

Diese Funktion formatiert einen mehrzeiligen Text, der in die Zwischenablage kopiert wurde, so, dass er per Paste direkt im Editor in ein M-File eingefügt werden kann:
Code:
function FormatClipText
% Format multiline text in the clipboard as a Matlab string.
% If you have copied a long multi-line text to the clipboard, pasting it to an
% M-file in the editor is tedious. This function add the required square brackets,
% quotes, continuations and commas, to get a valid Matlab string.
% Proceeding: Copy the text to the clippboard, run this function from the
% command line, paste the clipboard contents in the editor.
%
% Jan Simon, Heidelberg, (C) 2011
% BSD-License: Use, copy, modify freely on your own risk, mention the author.

% Get String from clipboard:
Str = clipboard('paste');
if isempty(Str)
  warning(['JSimon:', mfilename, ':NoText'], ...
     'Cannot convert clipboard to text!');
  return;
end

% Remove trailing line break
LF = char(10);
if Str(end) == LF
  Str(end) = [];
end

% Care for a single space at the end of each line:
% No REGEXPREP to support Matlab 6.5.
index = strfind(Str, [' ', LF]);
while ~isempty(index)
   Str(index) = [];
   index      = strfind(Str, [' ', LF]);
end

% Convert quote caracters:
Str = strrep(Str, char(39), char([39, 39]));

% Add square brackets and quotes:
Str = strrep(Str, LF, [' '', ...', LF, '    ''']);
Str = ['[''', Str, '''];'];

% Finally copy the formated string in the clipboard again:
clipboard('copy', Str);

Beispiel:
Code:
% Copied:
  Diese Funktion formatiert einen mehrzeiligen Text, der in die
  Zwischenablage kopiert wurde, so, dass er per Paste direkt
  im Editor in ein M-File eingefügt werden kann

% Call in the command window:
FormatClipText

% Pasted in the editor:
  ['  Diese Funktion formatiert einen mehrzeiligen Text, der in die ', ...
    '  Zwischenablage kopiert wurde, so, dass er per Paste direkt ', ...
    '  im Editor in ein M-File eingefügt werden kann'];

Gruß, Jan
Private Nachricht senden Benutzer-Profile anzeigen


denny
Supporter

Supporter



Beiträge: 3.853
Anmeldedatum: 14.02.08
Wohnort: Ulm
Version: R2012b
     Beitrag Verfasst am: 15.12.2011, 16:28     Titel:
  Antworten mit Zitat      
Sehr Nützlich! Danke!
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2024 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.