Rimozione dei primi 4 caratteri da una colonna insieme a un carattere specialeCiao,
Ho una colonna che è una descrizione di esempio e c'è sempre un ~numeri prima della descrizione che vorrei rimuovere da tutte le righe. Solo una riga contiene "~". Per esempio.
Campione:
126: Descrizione AB
291: Descrizione XYZ
~619: Descrizione
Esiste uno script JSL che rimuoverebbe "~", i primi numeri a 3 cifre e ":" (incluso lo spazio) da tutte le righe all'interno della colonna Sample? I dati che sto guardando hanno sempre numeri a 3 cifre nella parte anteriore insieme a : e spazio. Il problema è rimuovere ~ da una delle righe.
Apprezzo l'aiuto
Josh
Automazione e scriptingfinestreRi: Rimozione dei primi 4 caratteri da una colonna insieme a un carattere specialeEcco un modo, essenzialmente tagliando lo spazio iniziale dall'ultima "parola", usando ":" come delimitatore. Ci sono altri modi, incluso Regex.
/*JMP STATISTICAL DISCOVERY LLC (“JMP”) PERMITS THE USE OF THIS COMPUTER SOFTWARE CODE (“CODE”) ON AN AS-IS BASIS AND AUTHORIZES YOU TO USE THE CODE SUBJECT TO THE TERMS LISTED HEREIN. BY USING THE CODE, YOU AGREE TO THESE TERMS. YOUR USE OF THE CODE IS AT YOUR OWN RISK. JMP MAKES NO REPRESENTATION OR WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRIGEMENT, AND TITLE, WITH RESPECT TO THE CODE.
You may use the Code solely as part of a software product you currently have licensed from JMP, JMP’s parent company SAS Institute Inc. (“SAS”), or one of JMP’s or SAS’s subsidiaries or authorized agents (the “Software”), and not for any other purpose. The Code is designed to add functionality to the Software but has not necessarily been tested. Accordingly, JMP makes no representation or warranty that the Code will operate error-free. JMP is under no obligation to maintain, support, or continue to distribute the Code.
Neither JMP nor its licensors shall be liable to you or any third-party for any general, special, direct, indirect, consequential, incidental, or other damages whatsoever arising out of or related to your use or inability to use the Code, even if JMP has been advised of the possibility of such damages. Except as otherwise provided above, the Code is governed by the same agreement that governs the Software. If you do not have an existing agreement with JMP or SAS governing the Software, you may not use the Code.
JMP and all other JMP Statistical Discovery LLC product or service names are registered trademarks or trademarks of JMP Statistical Discovery LLC in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies.
*/
Names Default To Here (1);
//make data table
dt = New Table( "Untitled",
Add Rows( 3 ),
New Column( "Sample",
Character,
"Nominal",
Set Values(
{"126: Description AB", "291: Description XYZ", "~619: Description"}
)
)
);
//remove unwanted characters
for each row (dt,
:Sample = trim (word (-1, :Sample, ":"))
);Ri: Rimozione dei primi 4 caratteri da una colonna insieme a un carattere specialeCIAO @Prosciutti ,
Poiché la parte che vorresti mantenere è sempre separata dal resto della stringa da uno spazio vuoto, puoi usare una formula di ricodifica come sotto per mantenere tutte le "parole" tranne la prima (che è un mix di caratteri e numeri ma non separati da spazio vuoto). Puoi semplicemente cambiare il nome della colonna "Colonna 1" con il nome della colonna in cui hai la descrizione del campione.
Recode(
:Column 1,
{Word(
[2 -1],
_rcNow,
Get Whitespace Characters() ||
Get Punctuation Characters( Exclude Chars( "'-" ) ),
Unmatched( _rcNow )
)}
)
Spero che quest'altra opzione ti possa aiutare,
Ri: Rimozione dei primi 4 caratteri da una colonna insieme a un carattere specialeCi sono molti modi diversi per farlo, di seguito c'è un'opzione che usa regex
Regex("126: Description AB", "~?\d{3}: (.+)$", "\1");
Regex("291: Description XYZ", "~?\d{3}: (.+)$", "\1");
Regex("~619: Description", "~?\d{3}: (.+)$", "\1");
https://regex101.com/r/nMilGt/1 spiega un po 'la regex
