Removing unwanted characters from imported string

Hello,
I have a tab-delimited .txt file which I have to import into Indesign for further processing.
The file is composed by a 3 columns header row at the beginning (Code, Description, price) followed by a series of 3 columns data rows.
The problem is that sometimes, depending on the way the txt/csv file has been created, may include unwanted characters (such as spaces, double spaces, etc.).
Is there a way to "clean" the imported strings from these unwanted characters?
This is my starting code:
function processImportedTxt(){
    //Open .csv file
    var csvFile = File.openDialog("Open file .csv","tab-delimited(*.csv):*.csv;");
    datafile = new File(csvFile);
    if (datafile.exists){
        datafile.open('r');
   var csvData = new Array();
   while(!datafile.eof){//read every row till the end of file
        csvData.push(datafile.readln());
    datafile.close();
    for(a=1; a<csvData.length; a++){
        var myRowData = csvData[a];//row of data
        var mySplitData = myRowData.toString().split("\t");//divide columns
        var myRowCode = mySplitData[0];
        var myRowDesc = mySplitData[1];
        var myRowPrice = mySplitData[2];
        // Here goes code for cleaning strings from unwanted characters
processImportedTxt();
Any help would be much appreciated
Thanks in advance

Hi,
If you want to safe 1-space occurences just a small correction:
i.e.:
var myRowCode = mySplitData[0].replace(/\s\s+/g,'');
Jarek

Similar Messages

  • Remove unwanted chars from a string

    hi friends,
    mi special requirement is this:
    i have a string containing:
    "Jose[12] M[36]ller" and i only want to see [12][36] afterwards, so how could i remove the remaining characters ?
    Thank you!

    Hi Clemens,
      if u only want the data enclosed in the parentheses[] along with the parentheses then this program will work fine for you.  Check the same and get back to us. If u can elaborate ur reqmt then we can help in a better way.
    REPORT  zyh284_test2.
    DATA:
    w_string TYPE string VALUE 'Jose[12] M[36]ller',
    w_sub_string TYPE string,
    w_int TYPE i,
    w_char,
    w_counter TYPE i,
    fl_flag.
    w_int = STRLEN( w_string ).
    w_counter = 0.
    DO w_int TIMES.
      w_char = w_string+w_counter(1).
      IF w_char EQ '['.
        fl_flag = 'X'.
      ENDIF.
      IF fl_flag = 'X'.
        CONCATENATE  w_sub_string w_char INTO w_sub_string.
      ENDIF.
      IF w_char EQ ']'.
        CLEAR fl_flag.
      ENDIF.
      w_counter = w_counter  + 1.
    ENDDO.
    WRITE:w_sub_string.

  • Removing special characters from a string

    Hi All,
    I have this in one my column in my table
    ABC-DEF
    ABC/DEF
    ABC,DEF
    ABC DEF
    I want to remove -, /, comma and space so i want the result like this
    ABCDEF
    ABCDEF
    ABCDEF
    ABCDEF
    How can I do this in PL/sql.
    Thanks.

    Use REGEXP_REPLACE:
    with sample_table as (
                          select 'ABC-DEF' str from dual union all
                          select 'ABC/DEF' from dual union all
                          select 'ABC,DEF' from dual union all
                          select 'ABC DEF' from dual
    -- end of on-the-fly sample table
    select  str,
            regexp_replace(str,'[-/, ]') new_str
      from  sample_table
    STR     NEW_STR
    ABC-DEF ABCDEF
    ABC/DEF ABCDEF
    ABC,DEF ABCDEF
    ABC DEF ABCDEF
    SQL> SY.

  • How do you removing special characters from a string

    hi,
    i'm a novice to java, if you couldn't tell. i need to write a program to recognise palindromes (eg. madam etc.) but i can't work out how to strip or clean the input string of white space or punctuation. any help appreciated. by the way, any other ideas on how to go about it?? (i don't expect it to be done, just after guidance)
    my thanks in advance

    OK Here you are:
    protected static String removeJunk(String string)
              int i, len = string.length();
              StringBuffer dest = new StringBuffer(len);
              char c;
              for (i = (len - 1); i >= 0; i--)
                   c = string.charAt(i);
                   if (Character.isLetterOrDigit(c))
                        dest.append(c);
              return dest.toString();
    Klint

  • Removing unwanted characters..

    Hey guys,
    I'm back for help again. Unfortunately my brain isn't creative enough, so please help! :-)
    Ok, I need to remove unwanted characters from a file...the problem is that the characters look like this:
    in any text editor. I'm using JEdit, and it's ISO-8859-1 encoding. The text was initally from a html file, and i think that most of the html is displayed well as text in JEdit. But these squares, which are bits of info that I don't need, are making it a little trick to do my extraction.
    Ex: the word I want to extract is "trouble". But in the file, it looks like this:
    troble....
    Anyone know how to get rid of all that stuff???
    Thanks in advance.
    ...DJVege...

    you could try to set a filter on the characters you accept. Process each character and only accept those that fall into some ASCII boundary. If you accept ASCII characters that have values between 33-255, most blocks should be eliminated.
    Something like this should help:
    import java.io.*;
    public class Example {
         protected static final int MIN_ASCII = 33;
         protected static final int MAX_ASCII = 255;
         public Example(String file) throws IOException {
              BufferedReader b = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
              PrintStream p = new PrintStream(new FileOutputStream(file+"_fix.txt"));
              String s = "";
              int j;
              while ((s = b.readLine()) != null) {
                   for (j = 0;j < s.length();j++) {
                        if (valid(s.charAt(j))) {
                             p.print(s.charAt(j));
                   p.println();
              b.close();
              p.close();
         protected boolean valid(char c) {
              int asc = (int)c;
              // allow for tabs and spaces
              if (asc == 9 || asc == 32) {
                   return true;
              return (asc >= MIN_ASCII && asc <= MAX_ASCII);
         public static void main(String args[]) {
              if (args.length > 0) {
                   try {
                        new Example(args[0]);
                   catch (IOException e) {
                        e.printStackTrace();
    }useage: java Example <file>
    of course, something like this will probably only work on "english" files as I dont have an understanding on how foreign characters are encoded..
    if this doesnt solve your problem, you might want to adjust the range to 33-127, which will eliminate all "block" characters and all "special formatted" characters (i.e. accented characters, currency signs, etc.)
    see http://asciitable.com/ for more information on ASCII characters

  • Remove regular expression from a string

    Hello,
    I have a string like this
    @1test;'"{input+
    Please help me to remove special characters from the string.

A: remove regular expression from a string

Hi Krishna,
DATA : str TYPE STRING VALUE '@1test;"{}]input+',
            char,
            length TYPE i,
            index TYPE i.
length = STRLEN( str ).
WHILE length > index.
  char = str+index(1).
  WRITE char.
  if char CA '+-*/!`@#$%^&()_=[]{};'.               " Add/Remove here to include numbers
    REPLACE ALL OCCURRENCES OF char in str WITH ''.
    REPLACE ALL OCCURRENCES OF '"' in str WITH ''.  " characters "{}[] are not comparable
    REPLACE ALL OCCURRENCES OF '{' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '}' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '[' in str WITH ''.
    REPLACE ALL OCCURRENCES OF ']' in str WITH ''.
    length = STRLEN( str ).
    ENDIF.
  add 1 to index.
ENDWHILE.
WRITE str.
Add or remove special char from '+-*/!`@#$%^&()_=[]{};' in if part as per your requirement.
Hope it meets your requirement.
Do not forget to mark helpful/correct if ma answer is useful .
Thanks,
Karthik

Hi Krishna,
DATA : str TYPE STRING VALUE '@1test;"{}]input+',
            char,
            length TYPE i,
            index TYPE i.
length = STRLEN( str ).
WHILE length > index.
  char = str+index(1).
  WRITE char.
  if char CA '+-*/!`@#$%^&()_=[]{};'.               " Add/Remove here to include numbers
    REPLACE ALL OCCURRENCES OF char in str WITH ''.
    REPLACE ALL OCCURRENCES OF '"' in str WITH ''.  " characters "{}[] are not comparable
    REPLACE ALL OCCURRENCES OF '{' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '}' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '[' in str WITH ''.
    REPLACE ALL OCCURRENCES OF ']' in str WITH ''.
    length = STRLEN( str ).
    ENDIF.
  add 1 to index.
ENDWHILE.
WRITE str.
Add or remove special char from '+-*/!`@#$%^&()_=[]{};' in if part as per your requirement.
Hope it meets your requirement.
Do not forget to mark helpful/correct if ma answer is useful .
Thanks,
Karthik

  • Actively remove unwanted characters

    Hi, I'm writing a function to actively remove unwanted characters from an input field. It will run every time a key press event occurs on the selected input fields. It is going to remove quotes and things like that. This is what I have so far..
    void test(){
    char unwantedCharSet[50]={"abcD"};
    char tempString2[200];
    int matchedCharIndex;
    GetCtrlVal (panelHandle[MAIN], MAIN_STRING,tempString);
    do{
    RemoveSurroundingWhiteSpace (tempString);
    matchedCharIndex = strcspn (tempString, unwantedCharSet);
    if(matchedCharIndex==strlen(tempString)){
    SetCtrlVal (panelHandle[MAIN], MAIN_STRING, tempString);
    return;
    else{
    strncpy (tempString2, tempString, matchedCharIndex);
    CopyString (tempString, matchedCharIndex, tempString,matchedCharIndex+1,(strlen(tempString)-matchedCharIndex));
    strcat (tempString2, tempString);
    sprintf(tempString,"%s",tempString2);
    } while(1);
    return;
    It is still glitchy. Does anyone have any advice to efficiently do this?
    Thanks in advance!
    Solved!
    Go to Solution.

    This was my solution, although, it takes a long time to perform. Does anyone have any tips on a better (faster/cleaner) approach?
    /*=====================================================================*/
    // TEST
    /*=====================================================================*/
    void test(){
    GetCtrlVal(panelHandle[MAIN],MAIN_STRING,tempString);
    SetCtrlVal(panelHandle[MAIN],MAIN_STRING,filter(tempString,unwantedCharSet));
    return;
    /*=====================================================================*/
    // FILTER
    /*=====================================================================*/
    char *filter(char *inputString,char *filterString){
    int ptr=0,matchedCharIndex=0;
    char outputString[100];
    do{
    matchedCharIndex = strcspn (inputString,filterString);
    if(matchedCharIndex!=strlen(tempString)){
    strcpy (outputString, inputString);
    for(ptr=matchedCharIndex;ptr<=strlen(inputString);ptr++){
    outputString[ptr]=inputString[ptr+1];
    DebugPrintf("%s\n",outputString);
    if(outputString[ptr]=='\n'||outputString[ptr]=='\0')
    break;
    strcpy(inputString,outputString);
    else
    return inputString;
    } while(1);
    return inputString;

  • Removing non english characters from my string input source

    Guys,
    I have problem where I need to remove all non english (Latin) characters from a string, what should be the right API to do this?
    One I'm using right now is:
    s.replaceAll("[^\\x00-\\x7F]", "");//s is a string having chinese characters.
    I'm looking for a standard Solution for such problems, where we deal with multiple lingual characters.
    TIA
    Nitin

    Nitin_tiwari wrote:
    I have a string which has Chinese as well as Japanese characters, and I only want to remove only Chinese characters.
    What's the best way to go about it?Oh, I see!
    Well, the problem here is that Strings don't have any information on the language. What you can get out of a String (provided you have the necessary data from the Unicode standard) is the script that is used.
    A script can be used for multiple languages (for example English and German use mostly the same script, even if there are a few characters that are only used in German).
    A language can use multiple scripts (for example Japanese uses Kanji, Hiragana and Katakana).
    And if I remember correctly, then Japanese and Chinese texts share some characters on the Unicode plane (I might be wrong, 'though, since I speak/write neither of those languages).
    These two facts make these kinds of detections hard to do. In some cases they are easy (separating latin-script texts from anything else) in others it may be much tougher or even impossible (Chinese/Japanese).

  • Removing non-alpha-numeric characters from a string

    How can I remove all non-alpha-numeric characters from a string? (i.e. only alpha-numerics should remain in the string).

    Or even without a loop ?
    Extract from the help for the Search and Replace String function :
    Right-click the Search and Replace String function and select Regular Expression from the shortcut menu to configure the function for advanced regular expression searches and partial match substitution in the replacement string.
    Extract from the for the advanced search options :
    [a-zA-Z0-9] matches any lowercase or uppercase letter or any digit. You also can use a character class to match any character not in a given set by adding a caret (^) to the beginning of the class. For example [^a-zA-Z0-9] matches any character that is not a lowercase or uppercase letter and also not a digit.
    Message Edité par JB le 05-06-2008 01:49 PM
    Attachments:
    Example_VI_BD4.png ‏2 KB

  • Removing characters from a String (concats, substrings, etc)

    This has got me pretty stumped.
    I'm creating a class which takes in a string and then returns the string without vowels and without even numbers. Vowels and even characters are considered "invalid." As an example:
    Input: "hello 123"
    Output: "hll 13"
    The output is the "valid" form of the string.
    Within my class, I have various methods set up, one of which determines if a particular character is "valid" or not, and it is working fine. My problem is that I can't figure out how to essentially "erase" the invalid characters from the string. I have been trying to work with substrings and the concat method, but I can't seem to get it to do what I want. I either get an OutOfBoundsException throw, or I get a cut-up string that just isn't quite right. One time I got the method to work with "hello" (it returned "hll") but when I modified the string the method stopped working again.
    Here's what I have at the moment. It doesn't work properly for all strings, but it should give you an idea of where i'm going with it.
    public String getValidString(){
              String valid = str;
              int start = 0;
              for(int i=0; i<=valid.length()-1; i++){
                   if(isValid(valid.charAt(i))==false){
                             String sub1 = valid.substring(start, i);
                             while(isValid(valid.charAt(i))==false)
                                  i++;
                             start=i;
                             String sub2 = valid.substring(i, valid.length()-1);
                             valid = sub1.concat(sub2);
              return valid;
         }So does anybody have any advice for me or know how I can get this to work?
    Thanks a lot.

    Thansk for the suggestions so far, but i'm not sure how to implement some of them into my program. I probably wasn't specific enough about what all I have.
    I have two classes. One is NoVowelNoEven which contains the code for handling the string. The other is simply a test class, which has my main() method, used for running the program.
    Here's my class and what's involved:
    public class NoVowelNoEven {
    //data fields
         private String str;
    //constructors
         NoVowelNoEven(){
              str="hello";
         NoVowelNoEven(String string){
              str=string;
    //methods
         public String getOriginal(){
              return str;
         public String getValidString(){
              String valid = str;
              int start = 0;
              for(int i=0; i<=valid.length()-1; i++){
                   if(isValid(valid.charAt(i))==false){
                             String sub1 = valid.substring(start, i);
                             while(isValid(valid.charAt(i))==false)
                                  i++;
                             start=i;
                             String sub2 = valid.substring(i, valid.length()-1);
                             valid = sub1.concat(sub2);
              return valid;
         public static int countValidChar(String string){
              int valid=string.length();
              for(int i=0; i<=string.length()-1; i++){
                   if(isNumber(string.charAt(i))==false){
                        if((upperVowel(string.charAt(i))==true)||lowerVowel(string.charAt(i))){
                             valid--;}
                   else if(even(string.charAt(i))==true)
                        valid--;
              return valid;
         private static boolean even(char num){
              boolean even=false;
              int test=(int)num-48;
              if(test%2==0)
                   even=true;
              return even;
         private static boolean isNumber(char chara){
              boolean number=false;
              for(int i=0; i<=9; i++){
                   if((int)chara-48==i){
                        number=true;
              return number;
         private static boolean isValid(char chara){
              boolean valid=true;
              if(isNumber(chara)==true){
                   if(even(chara)==true)
                        valid=false;
              if((upperVowel(chara)==true)||(lowerVowel(chara)==true))
                   valid=false;
              return valid;
    }So in my test class i'd have something like this:
    public class test {
    public static void main(String[] args){
         NoVowelNoEven test1 = new NoVowelNoEven();
         NoVowelNoEven test2 = new NoVowelNoEven("hello 123");
         System.out.println(test1.getOriginal());
         //This prints hello   (default constructor string is "hello")
         System.out.println(test1.countValidChar(test1.getOriginal()));
         //This prints 3
         System.out.println(test1.getValidString());
         //This SHOULD print hll
    }

  • Removing Duplicate Characters in a String without using a Hashset

    I was wondering if anyone knew a way of removing duplicate characters in a string without using a Hashset.
    I want to go from
    helloworld -> helowrd

    okay, here it is
    1) use a loop, look through each character in the original string
    2) look at the new string, if this character exist, don't add it, otherwise add it.
    check out methods in java.lang.String

  • HT4915 I share my iTunes accont with my kids. Many of the songs that they purchase, I do not want in my iphone Library, and I don't want them to play when I have my phone on shuffle. How an I remove unwanted songs from my phone library?

    I share my iTunes accont with my kids. Many of the songs that they purchase, I do not want in my iphone Library, and I don't want them to play when I have my phone on shuffle. How an I remove unwanted songs from my phone library withot affecting their devices?

    These are the downsides of a shared library because if you delete the song from your library it will get also automatically  deleted from your kids library. If you want to proceed then please follow this guide: https://support.apple.com/kb/HT4915

  • How do I remove unwanted updates from the App Store?

    How do I remove unwanted updates from the App Store? So you understand better what I'm referring to:
    I have the App Store icon in the Dock. When there's an update a red number appears on said icon. Well, I went to check on the updates and it's for 4 different applications I either no longer have or use. One of them is an update for Lion OS users. I'm still on Snow Leopard, so it doesn't even apply to me.
    So there they sit... I'm not going to download the updates... so how do I get rid of them?

    Hi Andy ..
    no longer have or use
    If there are updates available for apps you have deleted, try this.
    Go to ~/Library/Caches/com.apple.appstore
    Move the Cache.db and Updates files from the com.apple.appstore folder to the Trash.
    Empty the Trash, restart your Mac.
    For any apps you still have installed but do not use, the updates will still be available from the Updates top of the App Store window and show on the red badge on the App Store icon in the Dock.
    edited by:  cs

  • How can I remove unwanted downloads from my macbook pro?

    How can I remove unwanted downloads from my macbook pro?

    Go to the Download folders as specified in the browser's or mail app's preferences and delete what you don't want to keep.

  • I need urgent help to remove unwanted adware from my iMac. Help!

    I need urgent help to remove unwanted adware from my iMac. I have somehow got green underline in text ads, pop up ads that come in from the sides of the screen and ads that pop up selling similar products all over the page wherever I go. Its getting worse and I have researched and researched to no avail. I am really hestitant to download any software to remove whatever it is that is causing this problem. I have removed and reinstalled chrome. I have cleared Chrome and Safari cookies. Checked extensions, there are none to remove. I need to find an answer on how to get rid of these ads. Help please!

    You installed the "DownLite" trojan, perhaps under a different name. Remove it as follows.
    Back up all data.
    Triple-click anywhere in the line below on this page to select it:
    /Library/Application Support/VSearch
    Right-click or control-click the line and select
    Services ▹ Reveal in Finder (or just Reveal)
    from the contextual menu.* A folder should open with an item named "VSearch" selected. Drag the selected item to the Trash. You may be prompted for your administrator login password.
    Repeat with each of these lines:
    /Library/LaunchAgents/com.vsearch.agent.plist
    /Library/LaunchDaemons/com.vsearch.daemon.plist
    /Library/LaunchDaemons/com.vsearch.helper.plist
    /Library/LaunchDaemons/Jack.plist
    /Library/PrivilegedHelperTools/Jack
    /System/Library/Frameworks/VSearch.framework
    Some of these items may be absent, in which case you'll get a message that the file can't be found. Skip that item and go on to the next one.
    Restart and empty the Trash. Don't try to empty the Trash until you have restarted.
    From the Safari menu bar, select
    Safari ▹ Preferences... ▹ Extensions
    Uninstall any extensions you don't know you need, including any that have the word "Spigot" in the description. If in doubt, uninstall all extensions. Do the equivalent for the Firefox and Chrome browsers, if you use either of those.
    This trojan is distributed on illegal websites that traffic in pirated movies. If you, or anyone else who uses the computer, visit such sites and follow prompts to install software, you can expect much worse to happen in the future.
    You may be wondering why you didn't get a warning from Gatekeeper about installing software from an unknown developer, as you should have. The reason is that the DownLite developer has a codesigning certificate issued by Apple, which causes Gatekeeper to give the installer a pass. Apple could revoke the certificate, but as of this writing, has not done so, even though it's aware of the problem. It must be said that this failure of oversight is inexcusable and has seriously compromised the value of Gatekeeper and the Developer ID program. You cannot rely on Gatekeeper alone to protect you from harmful software.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
    Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.

  • Maybe you are looking for