Adding/Removing from String kdb - kdb

I was doing some work to do with kdb and have been tinkering with strings and variables. I was just wondering if its possible to remove part of a string and add something to do the end of it.
s1:"Hello" s2:" World"
I have a joint string "Hello World" which I created using
s3:s1,s2
I was trying to remove the Hello and add something after the World in the joint string.
s3[1*til 6] = Hello
This allows me to select the Hello part of the string if this helps

you could use drop (_) to get rid of the "Hello" and join (,) to add on what you want. Something like
q)6_s3,"star Hiphop"
"Worldstar Hiphop"
If you didn't want to count the letters in the first word you could use vector from scalar (vs) to get a list of enlisted words and index into it, then join onto that:
q)(" " vs s3)[1],"star Hiphop"
"Worldstar Hiphop"
Hope this helps.

Strings are character lists, so the drop function _ will still work on them. For example 1_"Hello" will return ello.
So if you want to remove "Hello" from your string s3 you would use
q)5_s3
"World"
Adding something onto the end of this then requires the join operator ,, for example
q)s:"HelloWorld"
q)s1:"Mr. "
q)s2:5_s
q)s3:"wide"
q)s1,s2,s3
"Mr. Worldwide"

You could use the ssr function (string search replace).
q)s3:"HelloWorld"
q)ssr[s3;"Hello";""], " of War"
"World of War"

Related

regexp_extract is getting spaces

I have this sample data to test regexp_extract function.
message_txt="test 9341Come Products Preferred*TEST*TEST, the mfg SYSTEM, paid18.26 toward the"
message_txt="mfg of TR tt 100 test, paid $861.82 toward your "
message_txt="TEST 0.015% , paid $1119.00toward your "
I need to extract the numeric value between "paid" and "toward", i.e. 18.26, 861.82 and 1119.00. I execute the below statement
regexp_extract(col("message_txt"),"(?i)paid\\s+(.*?)\\s+(?i)toward",1)
... but getting only spaces.
I don't know regexp_extract() but it looks to me like...
You don't want $ in your results, so you need to move that outside of the capture group.
There aren't always spaces before/after the target, so \\s needs to be optional.
There's no point in having a 2nd (?i).
It's usually better to describe exactly what's permitted in the capture group.
Try something like: "(?i)paid\\s*\\$?([\\d.]+)\\s*toward"

Split string into two parts and concatenate with another column

My string columns look like this:
Name : AllenEdward
UniqID : 12345678
How can I get this output in my report?
Allen12345678 Edward
12345678 should be followed by 2 spaces.
The first thing to figure out the formulas that split the Name column. We don't know what your data looks like, so that's all you. You could write something that adds a space before any capital letters after the first, but you'll have trouble with the more complex last names like MacDonald.
Once you figure that out, it's a simple matter of using Formula Fields in Crystal. Something like:
[FIRST]{table.UniqID} & " " & [LAST]
...where [FIRST] and [LAST] are the results from your splitting formula.

LotusScript - How to escape double quotes in the SELECT statement?

I have a multiple documents which are containing the field named organization.
Almost every second document contains double quotes in this field, for example: Medical Center "James Goodwin Corp." e.t.c
I have a search query with the name of some organization, which also contains quotes and trying to use this name in the search query to find all needed documents.
I have tryed many variants and each time I am getting the query syntax error about double quotes.
Can you please give some small example or some advise how to escape double quotes in the SELECT statement?
Thank you!
Update:
Yes, I am using Replace function like this:
searchValue = Replace(docByUi.search(0),{"},{|"|})
to change this double quotes to |"|.
And I am getting an error in my select query
Or maybe I am wrong in something?
Update #2:
My query looks like this:
query = {Form="Person" & #Contains(} & docByUi.fields(0) & {;"} & searchValue & {")}
I meaned that I am already using {} to create a part-to-part query.
You can use curly braces {} in your search statement. You don't need to escape double quotes inside braces.
Here is example of your search query:
Form = "Person" & #Contains(Level0; {Filia "Department of Y"})
In your lotus script you can use | symbol to make your string:
query$ = |Form="Person" & #Contains(| & docByUi.fields(0) & |; {| & searchValue & |})|
Instead of using double quotes, use the pipe character:
Select #Contains(Organization; |"|);
Is that what you are trying to do?

Mysterious " " in Swift 4 print output (Xcode 9Beta)

I believe this is my first post here. I am teaching myself Swift and have come across some odd behavior involving the mysterious appearance of a leading " " in a print statement. I was exploring print formatting and this code is producing a leading " " in the first dashedLine printed.
Code:
var dashedLine = "-------------------------------------------------------------------"
print("a bunch of text\n", dashedLine)
print(dashedLine)
Output:
a bunch of text
-------------------------------------------------------------------
-------------------------------------------------------------------
Why the leading space before the first dashed line?
I've read the Swift 4 documentation. (In playing with "terminator" syntax at the end of a print list, I get unanticipated results, including suppression of output, depending.) I am curious as to the appearance of the leading space as my primary question.
By default, a print statement with multiple arguments prints those out with a space in between.
You can find more in Apple's documentation here.
Following on to #bajracharyas353’s answer, a solution if you’re needing to avoid this would be to combine strings using any of the methods Swift allows, like "a" + "b" or String.append, or print(String1, String2, separator: "").
As for suppression of output, I think I’ve run into the same thing with JWTs. There seems to be a pretty modest limit on output, but I could be wrong there.
Problem
The Swift.print(_ items: Any...) function prints multiple arguments separated by a space.
Solution
Use print("a bunch of text\n", dashedLine, separator: "") instead

Escape character in JPQL

In JPQL what is escape character we can use to escape characters such as "'"?
Ex : I am doing something like
...where person.name='Andy'
Here it is working fine
but when the person's name is Andy's then the where clause becomes like
...where person.name='Andy's'
and it returns an error saying
It cannot figure out where string literal ends. Solution is nicely told in specification:
A string literal that includes a single quote is represented by two
single quotes—for example: ‘literal’’s’.
In your case means:
...where person.name='Andy''s'
Below is the sample code for executing query using named parameter.
Query query = entityManager.createQuery("SELECT p FROM Person p WHERE p.name LIKE :name" );
query.setParameter("name", personName);
Here, you can pass string to personName which may contain special character like "Andy's".
Also, it looks much clean & doesn't require to check parameter before query execution & altering the search string.