I have a 2D char Array, needed to display on a View.
for example I have array as-
char charArray[4][10] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
' ',' ',' ', A,m,i,t ,' ', ' ',' ',
' ',' ',' ', K,u,m,a,r, ' ',' ',
9,8,7,6,5,4,3,2,1,0
}
I want to display this content of array on UIView(not on TextView) on some action like button clicked.
And also want add some observer that reload UIView when any element of charArray changed.
UIView doesn't provide any methods for rendering text. You should use an UI object that is made for this purpose like UITextView or UILabel.
The alternative would be to draw the text within a CGContext: CGContextShowTextAtPoint()
And since you are using a char-array and not an object you won't be able to implement an observer. You should consider creating your own class for that.
Related
With a for loop in VBA I would like to write values of an array into a table in ACCESS, but the array values has apostrophe, therefore the SQL is not working in VBA
Arr(1) = "Mother' love"
Arr(2) = "Father' love"
Arr(3) = "Value in 'Mother'"
Arr(4) = "Value in 'Father'"
For i = 1 To 4 Step 1
strSQL = "Insert into [Table1] (Content) Values (" & Arr(i) & ")"
Debug.Print strSQL
DoCmd.RunSQL strSQL
Application.RefreshDatabaseWindow
Next i
Errors as follow
Run-time error '3075'
Syntax error (missing operator) in query expression 'Mother's love)'
I'm building a graph based and some of the relationships are based on information in nested lists. The relevant nodes are (b:Bundle) and (o:Object); the bundles require certain objects with different quantities and qualities. The nested list that contains these requirements has the format [ [object1, quantity1, quality1], [object2, quantity2, quality2], ... ]
but in the .csv file that I'm using the field has the format
o1,qn1,ql1|o2,qn2,ql2|... The relationship I want to create is
(b)-[r:REQUIRES {quantity, quality}]->(o).
I've tried using various combinations of SPLIT, UNWIND, and FOREACH. A minimal example from my data set:
id: 1
requirements: 24,1,0|188,1,0|190,1,0|192,1,0
That is to say, (b:Bundle {id:1}) -[r:REQUIRES {quantity:1, quality:0}]-> (o:Object {id:24}) and so on.
LOAD CSV WITH HEADERS FROM 'file:///bundles.csv' AS line
WITH SPLIT( UNWIND SPLIT ( line.requirements, '|' ), ',') as reqList
MATCH ( o:Object { id:TOINTEGER(reqList[0]) } )
MATCH ( b:Bundle { id:TOINTEGER(line.id) } )
MERGE (b) -[r:REQUIRES]-> (o)
ON CREATE SET r.quantity = TOINTEGER(reqList[1]),
r.quality = TOINTEGER(reqList[2]);
The error this query gives is
Neo.ClientError.Statement.SyntaxError: Invalid input 'P': expected 't/T' (line 2, column 22 (offset: 78))
" WITH SPLIT( UNWIND SPLIT ( line.requirements, '|' ), ',') as reqList"
^
Assuming your CSV file actually looks like this:
id requirements
1 24,1,0|188,1,0|190,1,0|192,1,0
then this query should work:
LOAD CSV WITH HEADERS FROM 'file:///bundles.csv' AS line FIELDTERMINATOR ' '
WITH line.id AS id, SPLIT(line.requirements, '|' ) AS reqsList
UNWIND reqsList AS reqsString
WITH id, SPLIT(reqsString, ',') AS reqs
MATCH ( o:Object { id:TOINTEGER(reqs[0]) } )
MATCH ( b:Bundle { id:TOINTEGER(id) } )
MERGE (b) -[r:REQUIRES]-> (o)
ON CREATE SET r.quantity = TOINTEGER(reqs[1]),
r.quality = TOINTEGER(reqs[2]);
Trying to create a formula to turn a string of words separated by spaces into camelcase
Much smaller version:
=SUBSTITUTE(PROPER(TRIM(A1))," ","")
We just use PROPER to upper case and TRIM and SUBSTITUTE to remove spaces.
If we want lowerCamelCase,
By just REPLACEing the first character with lower case, We have:
=REPLACE(SUBSTITUTE(PROPER(TRIM(A1))," ",),1,1,LEFT(LOWER(TRIM(A1))))
Using REGEX:
=REGEXREPLACE(REGEXREPLACE(PROPER(A1),"\s*",),"^(\w)",LEFT(LOWER(TRIM(A1))))
=LOWER(LEFT(TRIM(A1)))®EXREPLACE(PROPER(TRIM(A1)),"(\w|\s)(\w*)","$2")
This should work:
=JOIN("",ArrayFormula(UPPER(LEFT(SPLIT(A3," ")))&LOWER(MID(SPLIT(A3," "),2,500))))
or to be more precise:
=JOIN("",ArrayFormula(UPPER(LEFT(SPLIT(A3," ")))&LOWER(REGEXEXTRACT(SPLIT(A3," "),".(.*)"))))
To do this the following formula works (where A3 is the cell)
tl;dr:
=IF(IFERROR(FIND(" ",A3)), CONCAT(SUBSTITUTE(LEFT(LOWER(A3), FIND(" ", A3)), " ", ""), SUBSTITUTE(PROPER(SUBSTITUTE(A3, LEFT(A3, FIND(" ", A3)), "")), " ", "")), LOWER(A3))
Annotated:
=IF( // if a single word
IFERROR( // test if NOT an error
FIND( // looking for a space
" ",
A3
)
),
CONCAT( // concat the first word with the rest
SUBSTITUTE( // remove the space
LEFT( // left of the find
LOWER( // lowercase the string
A3
),
FIND( // find the space in the string
" ",
A3
)
),
" ",
""
),
SUBSTITUTE( // remove spaces
PROPER( // convert string to capitals
SUBSTITUTE( // remove first word
A3,
LEFT( // left of the find
A3,
FIND( // find first space
" ",
A3
)
),
""
)
),
" ",
""
)
),
LOWER( // lowercase rest of the word
A3
)
)
Taking cue from all answers, sharing what I did as no one has mentioned it in the following exact way (transformation e.g. created_at => createdAt)
=REPLACE(SUBSTITUTE(PROPER(A5), "_", ""), 1, 1, LOWER(LEFT(A5, 1)))
The above formula is
Easy => uses simple to understand popular functions
Correct => works on empty cells too
Efficient => parses the "whole" string only ONCE
Most of the work is done using PROPER function except the last part to replace first character with its lowercase version
I have some spring-data-neo4j / ogm code that is unexpectedly failing.
public Member loadMemberBySocialMediaAccount(String connectionKey) {
String[] connectionKeyParts = connectionKey.split(":");
Filters filters = new Filters()
.add(new Filter("providerId", connectionKeyParts[0]))
.add(new Filter("providerUserId", connectionKeyParts[1]));
Iterator<SocialMediaAccount> socialMediaAccounts = session.loadAll(SocialMediaAccount.class, filters, 2).iterator();
return socialMediaAccounts.hasNext() ? socialMediaAccounts.next().getMember() : null;
}
When I dig into the ogm code I can see the following exception is thrown. Is this expected?
org.neo4j.ogm.session.result.ResultProcessingException: "errors":[{"code":"Neo.ClientError.Statement.InvalidSyntax","message":"Invalid input 'n': expected whitespace, comment, '.', node labels, '[', \"=~\", IN, IS, '^', '*', '/', '%', '+', '-', '<', '>', \"<=\", \">=\", '=', \"<>\", \"!=\", AND, XOR, OR, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, RETURN, UNION, ';' or end of input (line 1, column 72 (offset: 71))\n\"MATCH (n:`SocialMediaAccount`) WHERE n.`providerId` = { `providerId` } n.`providerUserId` = { `providerUserId` } WITH n MATCH p=(n)-[*0..2]-(m) RETURN p, ID(n)\"\n ^"}]}
Just checked the tests, and what is expected is that all filters except the first must have a BooleanOperator defined (AND or OR).
So in your case:
Filters filters = new Filters()
.add(new Filter("providerId", connectionKeyParts[0]));
Filter providerUserIdFilter = new Filter("providerUserId", connectionKeyParts[1]);
providerUserIdFilter.setBooleanOperator(BooleanOperator.AND);
filters.add(providerUserIdFilter);
I've opened https://github.com/neo4j/neo4j-ogm/issues/73 to for us to figure out whether it is feasible to default the BooleanOperator for subsequent filters to AND.
I need trim all elements in a list in groovy or grails?
what is the best solution
Assuming it is a list of strings and you want to trim each string, you can do it using the spread operator (*.)
list = [" abc ", " xyz "]
list*.trim()
You can use the collect method or the spread operator to create a new list with the trimmed elements:
def strs = ['a', ' b', ' ']
assert strs.collect { it.trim() } == ['a', 'b', '']
assert strs*.trim() == ['a', 'b', '']
In those cases, the original list isn't modified. If you want to trim the strings in place, you'll need to iterate through the list with an index:
for (i in 0..<strs.size()) {
strs[i] = strs[i].trim()
}