Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree with David Thomas, when he says that you should fix problem in the CSV generation script.</p> <p>But if you don't have control over that script, you can use <a href="http://www.w3schools.com/jsref/jsref_obj_regexp.asp" rel="nofollow">regular expressions</a> in the javascript <a href="http://www.w3schools.com/jsref/jsref_replace.asp" rel="nofollow"><code>replace()</code></a> to replace the first occurrence of a comma with an empty string (removing it):</p> <pre><code>", 111 , andro1 , developer ,".replace(/^,/, ''); </code></pre> <p>that returns:</p> <pre><code>" 111 , andro1 , developer ," </code></pre> <hr> <p><strong>Update:</strong></p> <p><a href="http://jsfiddle.net/UTkwX/" rel="nofollow"><strong>Here</strong></a> you can see a demo of a javacript that removes the first comma and justifies all columns to a predefined max width.</p> <p>Since you don't have a jQuery tag, I am assuming you want pure Javascript, but keep in mind that with jQuery would be much easier.</p> <p>The final output you can see from the demo, is</p> <pre><code> EmpID, EmpName, EmpTitle, 111, andro1, developer, 112, andro2, developer, 113, andro3, developer, </code></pre> <p>In this case I am right justifying each column to 10 characters.</p> <p>About the bold in columns title, that is not possible in CSV format, because CSV is a plain text format. You might consider for this <a href="http://www.python-excel.org/" rel="nofollow">xlwt</a>. </p> <p>Again, I agree that you should solve this formatting problem from the generating script, but if you are just the consumer of those files and want to fix them in javascript, then this solution should work for you.</p> <hr> <p><strong>Update 2</strong> You need to clean that javascript. Please read the regexp link that I included above.</p> <p>You can replace this:</p> <pre><code>a = a.replace(/&lt;\/td&gt;/g, ","); a = a.replace(/&lt;\/TD&gt;/g, ","); a = a.replace(/&lt;\/th&gt;/g, ","); a = a.replace(/&lt;\/TH&gt;/g, ","); </code></pre> <p>with simply this:</p> <pre><code>a = a.replace(/&lt;\/t(d|h)&gt;/gi, ''); </code></pre> <p>And why are you replacing <code>&lt;/tr&gt;</code> and <code>&lt;/TR&gt;</code> with <code>--newline--</code> and then again you replace <code>--newline--</code> with <code>\n</code>? You could simply do this in a single call:</p> <pre><code>a = a.replace(/&lt;\/tr&gt;/gi, '\\n'); </code></pre> <p>So, I think you end up having a single string with all csv content, where each row is separated by a <code>\n</code>. </p> <p><a href="http://jsfiddle.net/XSKHX/1/" rel="nofollow"><strong>Here</strong></a> is the updated script to handle this use case. I only changed the <code>var</code> declaration, the core remains the same.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload