Formula output replaces tab (\t) with space

My use case: I paste some data into an input field and then ask GPT-3 (via the OpenAI pack) to turn the data into a tab-separated table. You use the \t code to instruct GPT-3 to use tab characters.

It works perfectly in the OpenAI playground. But in Coda the tabs get replaced by spaces, so it’s not actually a table.

I tried using Character(9) instead of \t but not only does it mess with GPT’s output, it still doesn’t output tabs in Coda.

Does anyone have a solution?

Screenshot:

Hi @Anna_F :blush: !

I’ve discovered more than a year ago that Character(9) was in fact, never really supported in Coda and that it was converted into spaces on paste :innocent: .

So, this is the expected behaviour.

I guess the only possibility would be to replace any tab character by the needed amount of spaces ?

I’m not sure if it will solve your issue though :no_mouth:

Alright, good to know. But no, using a lot of spaces won’t work. I don’t think there’s any number of spaces that will split text into columns when I paste onto Excel or a Coda table, is there? Only tabs can do that, as far as I know.

Hmm :thinking:

I’m currently not in front of my computer but what’s your use case here precisely ?

I mean what’s the purpose of your Copy Table field ? :innocent:

I was somewhat able to re-introduce the tabs between the “column” (using a mix of Split() and RegexReplace() but I don’t know if that’s what you’re looking for :innocent:

The goal is to copy a table in a format that can be pasted onto a spreadsheet or Coda table. In order for the pasted content to have distinct columns, the columns need to be separated by tabs. However, Coda replaces tabs with spaces in the formula output.

To understand what I mean, you can try copying some columns from a spreadsheet and pasting them onto Word. You will see that tabs are used to separate the columns.


Could you elaborate on using Split() and RegexReplace()? I am not very familiar with them and am not sure how I could use them to achieve what I need.

Hi @Anna_F :blush: !

Sorry for the late reply :smiling_face: .

Before going into the formula part, I thought about something that might simplifies things a little :

Did you try to paste the output you get from GPT using :

⌘ cmd/ctrl on Windows + ⇧ shift + v (which is the shortcut for Paste and match style on Chrome or any other browser I think)

or did you use

⌘ cmd/ctrl + v (which well, simply paste)

?

I’m asking because using one or the other could give different result :innocent:
(But it still might not solve the issue though :innocent: )

Yes :blush: !

In the sample you’ll find below, I tried my best to reproduce the output you get from GTP once pasted into a text field in Coda.

This is the value in the field called [Input - Spaces instead of tabs] in the table [Spaces > Tabs].

I assumed , from your screenshot, that each line representing a “row” was separated by a newline ("\n") and because only the spaces between the “columns” in each of these rows are the ones we’re interested in, the first step is to replace each newline in the whole text value pasted from GPT by something else, something easily identifiable (here I chose a comma (",") but it could be any character, as long as it’s a character you don’t use anywhere else in the output you pasted from GPT)

This is done in the field [1 - RegexReplace() "\n" by ","] with this formula :

thisRow.[Input - Spaces instead of tabs].RegexReplace("\n",",")

where RegexReplace() checks each character in thisRow.[Input - Spaces instead of tabs] and replace each newline character it finds ("\n") by a simple comma (",").

This outputs another text value as a whole (another entire string)

We can then Split() this text value by the commas to create a list of text values where one text value in the list is a “row” from the “table” you pasted.

This is done in the field 2 - Split() and the formula is one :

thisRow.[1 - RegexReplace() "\n" by ","].Split(",")

And now, the last step would be to finally replace the spaces between the “columns” for each text value (“row”) in the list of text values Split() returned :blush: .
(Note In Coda, each of these text values in the list is stored as/represented by CurrentValue)

Which is done with this formula :

thisRow.[2 - Split()].ForEach(
  CurrentValue.RegexReplace("\s",Character(9))
).Join(LineBreak())

Which takes the list of text values Split() previously outputted and for each (ForEach()) text value in the list (CurrentValue), we ask RegexReplace() to go through each character, find any spaces ("\s") and replace them by a tab (Character(9)).

And because ForEach() always outputs a list (of text values in this case), we Join() each item in the list by a LineBreak() :blush: .

The All in one formula is this one :

thisRow.[Input - Spaces instead of tabs]
  .RegexReplace("\n",",").Split(",").ForEach(
     CurrentValue.RegexReplace("\s",Character(9))
).Join(LineBreak())

The output of the formula can be copied and pasted to be directly converted into a brand new table, as long as you use ⌘ cmd/ctrl + ⇧ shift + v to “Paste and match style:blush:

Spaces to Tabs

Now, as it seems that you can ask GPT to format its output maybe, if you know you’ll be using the output in Coda, you could directly ask for a different format, something that would require less steps in the conversion/manipulation of the initial string :innocent: .

E.g.: Have each “row” separated by a comma and each “column” separated by a pipe (|)
(See the table [Input - Different formatting] below the 1st table in the sample)

This would suppress the need for the very first RegexReplace() and the formula could look like :

thisRow.[Input - Different formatting].Split(",").ForEach(
  CurrentValue.RegexReplace("\|",Character(9))
).Join(LineBreak())

(In RegEx, a pipe (|) needs to be escaped ("\|") to be considered as a character, as it has a special meaning/use)

Note that because I had to assume how the output you get from GPT is formatted, this might not work at the 1st try :innocent: .
(In that case, don’t hesitate to share a sample doc with the exact formatting you get from GPT)

In the meantime, I hope this helps :blush:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.