Remove spaces after commas in Google Sheets - arrays

I would like to ask if there is some shortcut/function how to remove all spaces after commas in Google Sheets?
Here is link to a template https://docs.google.com/spreadsheets/d/1jweedL8iURMfi-CNYDiRQRb0GZO2ji9cyTTTMf6pFk4/edit?usp=sharing.
I have a sheet which contains many data looking like this (more words in one section, separated by commas and there is space after each comma). However, I need the sections without the spaces after commas (e.g. "dog,cat"). I would like to apply it on the whole sheet.
Any suggestions, please?
Thank you very much.

If you're looking for a formula to do this, try this in cell C1:
=arrayformula(regexreplace(A:B;",\ ";","))
So if you wanted a new Sheet Hárok2 to copy Hárok1, you'd add this to cell A1 on Hárok2:
=arrayformula(regexreplace('Hárok1'!A:Z;",\ ";","))

Just go to Edit then Find and replace. Enter , in Find and enter , in Replace then go and Replace either one by one or everything in one go.

Related

Replace All and reduce text string

I have Google Forms results from live workshops that I want to edit in Sheets. I then want to calculate averages, pivot etc. to explore the data for insights.
I want to clean and standardize the data. I'd like to replace a series of long strings and reduce them just to their leading number:
UPDATE as requested here is a View-only sample Sheet with raw data on 1st tab, and how I'd like it to be formatted (2nd tab)
https://docs.google.com/spreadsheets/d/1pP8YV3oJXWGt3-88qgzMuup1pm1IsIgD4SHDL09MXrc/edit?usp=sharing
Example:
I'm aware of certifications I should be starting.
Replace with
3
Example 2:
I'm currently progressing a powerful certification.
Replace with:
4
In Excel I would simply use * as wildcard for the rest of the string, but Sheets appears different. I've read documentation and posts about regular expressions etc. and I'm not sure if that's overkill or how to proceed.
I'd THEN like to create a macro which does that for the whole sheet:
All strings which begin with 1)*
--> Replace with 1
All strings which begin with 2)*
--> Replace with 2
try:
=REGEXEXTRACT(A1; "^\d+")

How do I Text join multiple cells in an array formula in google sheets

I'm having trouble with the last part of a formula on Google Sheets.
In one column (B) I have cells occupied with different themes. These could be singular or have multiple themes in the cell separated by a comma. I'm matching these themes to theme headings and then taking the cells next to it in Column A (which contains names), combining them in a cell together to create a list of names associated with the theme.
I have managed to do this successfully if the cell only contains one theme, however if there are multiple themes separated by a comma then it doesn't work. I'm currently using =ArrayFormula(textjoin(", ",true,(IF($B$3:$B$8=F2,$A$3:$A$8,""))))
I have tried loads of things and feel like the answer is simple, but can't quite put my finger on it.
Here is the sheet - https://docs.google.com/spreadsheets/d/1dcDPN34qy1zAVZMxidd_zsurMU0Nv4zuA0YtMGAiFB0/edit#gid=0
Thanks for your help!
Try in E3
=if(REGEXMATCH($B3,E$2),$A3,)
if you want to get all together
=textjoin(char(10),,query(arrayformula(trim(split(flatten($A$3:$A&"~"&split($B$3:$B,",")),"~"))),"select Col1 where Col2='"&E$2&"' ",0))

Xtrareport DevExpress Keep Table together with the first record

I have some data that I want to be displayed the following way and I cannot find how to do it:
For example this would be the keep together case:
But I don't like that I have a lot of blank spaces when data is too much, so I would like the following to happen if possible.
When the colNames and the first row can fit in the remaining space put them there.
Or if more can fit after the first row, put all of them there and split where it is possible if necessary.
Basically I want a 'Keep together' option for the columns and first row, and everything else can be splitted at any point.
If anyone wants to achieve the same functionality do the following:
Put the table column names inside a GroupHeader and set its GroupUnion property to WithFirstDetail.
Put the table rows in the Detail next to the GroupHeader.
By doing this the WithFirstDetail property, as the name suggests, will try to keep the header with the first record, or move to the next page. Therefore achieving the behavior described above.

SSIS Text Qualifier not working correctly

I have a CSV file I am importing through SSIS.Below is an sample of the data in my file
"MEM1001","OTHER","P" ,20101001,20781231,,20781231,20101001,
"Medic","General >21" ,
"A100100" ,"2210",20101001,20781231
I have added , as column delimiter and " as Text Qualifier in the connection manager.
But columns like "P" ,"Medic","General >21" ,"A100100" , are still coming enclosed with double quotes when I preview the data while rest the of the string columns are coming without double quotes.
I am guessing it has something to do with the spaces after the quotes.
Can somebody explain why this is happening and how can i make this columns to come without double quotes while importing the data from file to table.
I just stumbled across this post, I had the same issues, I was trying around and could not find any other solution.
The text qualifier " only works in csv files, when the quote is directly after the colon, no space after the colon and the text identifier/qualifier. I have no idea why.
If you aren't able to fix the input data, an option would be to create a derived column and to replace the double quotes.
This worked for me:
How to replace double quotes in derived column transformation?
Trim(REPLACE(COLA, "\"", ""))
You should also add the Trim(), otherwise you have empty spaces before and maybe after the word. This could be problematic in a merge join (in my case it was).
I don't know why this extra spaces cause this issue.
Here is what I would do. It may not be the best idea, but it should work.
You will need to add script task before data flow task that would replace all " ," and ", " to ",".
Thank you
Why not just go to the Connection Manager for that csv file, click on Columns, and under the Column delimiter box just enter a space followed by a comma? Worked for me.

Fix CSV file with new lines

I ran a query on a MS SQL database using SQL Server Management Studio, and some the fields contained new lines. I selected to save the result as a csv, and apparently MS SQL isn't smart enough to give me a correctly formatted CSV file.
Some of these fields with new lines are wrapped in quotes, but some aren't, I'm not sure why (it seems to quote fields if they contain more than one new line, but not if they only contain one new line, thanks Microsoft, that's useful).
When I try to open this CSV in Excel, some of the rows are wrong because of the new lines, it thinks that one row is two rows.
How can I fix this?
I was thinking I could use a regex. Maybe something like:
/,[^,]*\n[^,]*,/
Problem with this is it matches the last element of one line and the 1st of the next line.
Here is an example csv that demonstrates the issue:
field a,field b,field c,field d,field e
1,2,3,4,5
test,computer,I like
pie,4,8
123,456,"7
8
9",10,11
a,b,c,d,e
A simple regex replacement won't work, but here's a solution based on preg_replace_callback:
function add_quotes($matches) {
return preg_replace('~(?<=^|,)(?>[^,"\r\n]+\r?\n[^,]*)(?=,|$)~',
'"$0"',
$matches[0]);
}
$row_regex = '~^(?:(?:(?:"[^"*]")+|[^,]*)(?:,|$)){5}$~m';
$result=preg_replace_callback($row_regex, 'add_quotes', $source);
The secret to $row_regex is knowing ahead of time how many columns there are. It starts at the beginning of a line (^ in multiline mode) and consumes the next five things that look like fields. It's not as efficient as I'd like, because it always overshoots on the last column, consuming the "real" line separator and the first field of the next row before backtracking to the end of the line. If your documents are very large, that might be a problem.
If you don't know in advance how many columns there are, you can discover that by matching just the first row and counting the matches. Of course, that assumes the row doesn't contain any of the funky fields that caused the problem. If the first row contains column headers you shouldn't have to worry about that, or about legitimate quoted fields either. Here's how I did it:
preg_match_all('~\G,?[^,\r\n]++~', $source, $cols);
$row_regex = '~^(?:(?:(?:"[^"*]")+|[^,]*)(?:,|$)){' . count($cols[0]) . '}$~m';
Your sample data contains only linefeeds (\n), but I've allowed for DOS-style \r\n as well. (Since the file is generated by a Microsoft product, I won't worry about the older-Mac style CR-only separator.)
See an online demo
If you want a java programmatic solution, open the file using the OpenCSV library. If it is a manual operation, then open the file in a text editor such as Vim and run a replace command. If it is a batch operation, you can use a perl command to cleanup the CRLFs.

Resources