In OOCalc I want to use the CONCATENATE function to add quotes to each string in column A.
So in cell B1 I want to do:
=CONCATENATE("\"",A1,"\"")
OOCalc does not like this, or without the escaping backslash.
Does anyone know how to do this, or what an alternative method might be?
This works for me:
=CONCATENATE("""",A1,"""")
Repeating the quotes escapes them (as it does in Visual Basic, I believe), so """" reads as: 'one quote to start a string, one escaped quote (""), then one quote to finish the string'.
Use char(34) to get the quote character.
CONCATENATE(char(34); B2; char(34))
Identical to the above but without the function:
="""" & A1 & """"
You can do it in 2 ways,
By using =CHAR(34) in the places of doible quotes
eg: =CONCATENATE("coffee",CHAR(34),"code")
By concatenating cell values
Steps
Set the cell value as double quotes -> "
Concatenate that cell in the string, wherever you need double quotes.
eg: E1 = "
F1 = =concatenate("coffee",E1,"code")
Thank you
You can use single quotations marks within the double quotation marks and vice versa.
Related
Overview
I am trying to create a User Defined Function where I want to pass three strings (cell values) — Value1, Value2 and Value3, pass them to an array and then use the Join Function to concatenate them using a New-Line character and adding a custom text as prefix before each string.
Target
But before I join them, I want to ensure none of the parameters passed are empty strings. I am trying to use VBA Filter function to detect non-empty strings passed in the array and then join them.
Where am I getting stuck
However, if I pass "" or vbNullString as Match parameter and set the Include parameter to 'False', the VBA Filter function is not able to detect non-empty strings. I have also used the Trim function to ensure that none of the strings passed in the array contain whitespaces.
Can I use some wildcard characters to ensure that the strings contain at least one or more characters? I have tried passing "*?" characters in the Match argument and set Include parameter to 'True' but it does not work.
Question
Is there a possible way to use VBA Filter Function, possibly with wildcard characters?
Via function GetInfotext() I demonstrate how to
use a ParamArray argument,
filter out empty strings by help procedure RemoveEmpty (see a),
concatenate custom prefixes with the found non-empty strings (see b).
Example call
Sub ExampleCall()
Debug.Print GetInfotext("Intro", "", "bla bla")
End Sub
Function GetInfotext(ParamArray s()) As String
Dim tmp: tmp = s
'a) get non-empty elements
RemoveEmpty tmp
'b) add custion prefixes
AddPrefixes tmp, s
'c) return entire text
GetInfotext = Join(tmp, vbNewLine)
End Function
Result in VB Editor's immediate window:
X: Intro
Z: bla bla
Help procedures to GetInfoText
The main requirement in OP is to filter out empty string elements; as blanks would be found in any element and there are no special wild cards for them, it's necessary to identify empty elements by an
unused unique character, e.g. $, so eventual negative filtering allows to remove these marked elements.
Note that the double replacement is necessary to allow to mark consecutive empty elements by the $ mark, as VBA would skip several replacing characters here.
Sub RemoveEmpty(arr)
Dim tmp
tmp = Replace(Replace(Join(arr, "|"), "||", "|$|"), "||", "|$|")
arr = Filter(Split(tmp, "|"), "$", False)
End Sub
In order to check how to add the found elements to your custom prefixes, you might use the following help procedure:
Sub AddPrefixes(tmp, ParamArray s())
'define custom prefixes -- change to your needs
Dim prfx() As Variant
prfx = Array("X: ", "Y: ", "Z: ")
'concatenate them with passed non-empty elements
Dim i As Long, ii As Long
For i = LBound(prfx) To UBound(prfx)
If Len(s(0)(i)) Then tmp(ii) = prfx(i) & tmp(ii): ii = ii + 1
Next
End Sub
I'm trying to work through and insert some data into a table that contains an array
INSERT INTO SUBURB VALUES (
'Perth',
'5684',
SDO_GEOMETRY(
2003,
NULL,
NULL,
SDO_ELEM_INFO_ARRAY(1,1003,1)
SDO_ORDINATE_ARRAY(391209,6464720 390919,6463010 392833,6463280 392902,6464290 391209,6464720)
)
);
I'm getting syntax error on the SDO_ORDINATE_ARRAY line and can't work it out.
The following syntax is wrong
SDO_ORDINATE_ARRAY(391209,6464720 390919,6463010 392833,6463280 392902,6464290 391209,6464720)
The general format of an array in postgressql is
'{ val1 delim val2 delim ... }'
if this is a one dimension array replace the whitespace with a comma.
If you want to store a multi dimension array use curly brackets
e.g.
'{{1,2,3},{4,5,6},{7,8,9}}'
Reference https://www.postgresql.org/docs/9.1/arrays.html
To write an array value as a literal constant, enclose the element
values within curly braces and separate them by commas. (If you know
C, this is not unlike the C syntax for initializing structures.) You
can put double quotes around any element value, and must do so if it
contains commas or curly braces. (More details appear below.) Thus,
the general format of an array constant is the following:
I am reading a text file and splitting the data string at each space using the following code.
L = f.ReadLine
If L = "" Then GoTo errorpoint:
On Error GoTo errorpoint:
sl = Split(L, " ", -1)
However, the array I get back takes, for example, the word "Contact" in the text file and turns it into " C o n t a c t " in a single cell of my array (see below) and I'm not sure why.
Data Output in VBA Watch Window:
I have tried using
For i = 0 To UBound(sl)
sl(i) = Replace(sl(i), " ", "")
Next
Afterwards to remove the spaces, but that doesn't appear to be removing the spaces from my data. Any ideas how I can prevent the code from adding a space between every character in the first place?
I then need to check whether sl(1) and sl(2) contain the words "Contact" and "Stress" respectively, but that condition cannot be met currently, the cells contain " C o n t a c t " and " S t r e s s ", so I changed the if loop to reflect that, but the condition is still not met.
In addition, I cannot convert my data from String > Double because of the unusual formatting, it seems.
As #LocEngineer pointed out in the comments, during the update of the external software that produces the text file I was reading, the text encoding had been changed to UTF-16 and the additional characters between my data were chr(0) Null values from the ASCII table, not spaces (chr(32) in ASCII).
For i = 0 To UBound(sl)
sl(i) = Replace(sl(i), Chr(0), "")
Next
This snippet solved the problem.
I have a cell array. Some of the elements in this cell array contains zeros as the first character and the whole element is only numbers (double) as well. When exporting these to Excel (which I prefer), the zeros are deleted and converting it to a number.
Let's take an example to illustrate my problem. I have a cell array with 10 elements:
NodeID = {'0000006';
'0000011';
'000011R';
'000016R';
'000021R';
'B276_2';
'EB 7.55';
'EB2521';
'EllebaekOPlB1';
'EllebaekOplB10'};
The first two elements contains zeros until the number 6 and 11, respectively. Unlike the third element and so forth, where letters are involved. So when exporting NodeID to Excel, it returns this in a column (I use writetable command by the way):
6
11
000011R
000016R
000021R
B276_2
EB 7.55'
EB2521
EllebaekOPlB1
EllebaekOplB10
Notice the removal of zeros for the first two elements. Now I know that in Excel, it will keep all the content with the addition of a quote symbol ' in front of the cell, eg. '0000006 for the first element.
I have searched in many places to find a solution to this. But is there a good way to avoid this from happening? Either by somehow adding an extra ´ or some other magical trick which I have not seen?
Thank you in advance!
One alternative (if your values are in a cell, as you say they are):
filename = 'NodeID.xlsx';
NodeID2 = cellfun(#(C) ['''',C], NodeID,'UniformOutput', false)
xlswrite(filename, NodeID2)
This gives you:
NodeID2 =
''0000006'
''0000011'
''000011R'
''000016R'
''000021R'
''B276_2'
''EB 7.55'
''EB2521'
''EllebaekOPlB1'
''EllebaekOplB10'
And an Excel file looking like this:
The cellfun line is equivalent to:
for ii = 1:numel(NodeID)
NodeID2{ii,1} = ['''', NodeID{ii}];
end
The part ['''', NodeID{ii}] inserts a single quotation mark in front for the string. Relevant answer.
I am calling one .NET app from another using Process.Start and passing in a bunch of strings as command line arguments:
startInfo.Arguments = String.Join(""" """, MyArray)
Dim p As Process = Process.Start(startInfo)
My intent is to pass in something like:
"first value" "second value" "third value"
and retrieve from within the second app:
Sub Main(ByVal args() as String)
If args.Length > 0 Then
End If
...
End Sub
Unfortunately args.Length only returns 1 - all the values I pass get passed on as a single value: "first value second value third value"
I tried wrapping each in double quotes in the first app but does not seem to help. I know I can just retrieve args(0) and then split it into an array of values but I do not want to do that. Also somehow it worked for me before, even without double quotes. So I am trying to figure out what happened and how can I make it pass my strings as multiple values instead of 1.
Your String.Join is not going to give you what you want. It will not put the double quote at the start and end of the string.
startInfo.Arguments = """" + String.Join(""" """, MyArray) + """"