I think there is a bug with the #replace helper where, if the "haystack" param (the input string) does not contain the "needle" param (the string to search for), the output is an empty string rather than the original string. I would expect the helper to return the original string if no match is made.
For example, this will return an empty string:
{{!-- where value="sometext", as in: {"value":"sometext"} --}}
{{#replace " " value}}+{{/replace}}
If that is the expected behavior, how can I call #replace when I don't know whether the input string will contain the value I want to replace?
Note that this example works as expected:
{{!-- where value="some text", as in: {"value":"some text"}
this correctly returns "some+text" --}}
{{#replace " " value}}+{{/replace}}
I figured out what the proper usage of the #replace helper is by finding an example in the Cornerstone theme. It looks like returning an empty string when there is indeed no match is the expected behavior, and to handle the no-match case an {{else}} is needed.
So, modifying my original example, this would be the proper usage:
{{#replace " " value}}+{{else}}{{value}}{{/replace}}
Related
We have used this option( Edit -> Find -> Find in Path) to search a string using IntelliJ. Currently, if we type to search a string, it will return the lines which contain the given string. But I want to find the lines which contain the given string and/or some pattern. Is there such a facility available in IntelliJ Idea?
Assume, We are going to search a string from the below lines
Test123456
Test12345
Sampletest12356
Search String: test*6
Expected output: Test123456
Search String: *test*6
Expected output: Test123456 , Sampletest12356
You should turn on the "Regex" checkbox and type in a proper regular expression in the search field, that's all. If I understood correctly, for your examples the correct requests would be test.*6 and .*test.*6 respectively.
<a>
This is <var>Me</var> and That is <var> You</var>
</a>
I can find an element "a" which contains "This is" by following code:
//a[contains(text(),'This is')]
But I am not able to find element "a" which contains "This is Me and That is You".
//a[contains(text(),'This is Me and That is You')]
Is there a way to find an element with children text as well?
I am not sure if this what you need but you can use string() to get the result as required,
//a[string()='This is Me and That is You']
The caveat however will be that you need to have precised information about the String being used.
See working example here.
This also can be find using normalize-space() function of xpath which strips leading and trailing white-space from a string, replaces sequences of whitespace characters by a single space, and returns the resulting string as below :-
//a[normalize-space()='This is Me and That is You']
Right now I'm trying to check if the pass is right when reading the file, but the problem is I have a "Pass:" String in front of the pass.
writeFile.WriteLine("Pass: " + Me.txtCPass.Text) ' pass
Me.txtPassword.Text = (GetLine(FILE_NAME, 2))
Not sure how I would just skip over the "Pass: " and just get right to the pass.
Supposing that GetLine returns a string then
Me.txtPassword.Text = GetLine(FILE_NAME, 2).Substring(6)
Substring is a method of the string class. It returns part of the string instance for which is called.
You could pass a starting index and the method returns the remainder.
Or you could also pass a length to force the method to return a defined part inside the instance
Here on MSDN you could find a detailed description
Me.txtPassword.Text = GetLine(FILE_NAME, 2).Substring(6)
I have created a calculated column which creates a URL which calls a Column called "Pitch Name" and from that will create the URL but I have to remove the space/spaces between words from pitch which needs to be displayed as a URL. Example of this is "Coca Cola" needs to be "CocaCola" so the site name can be"http://sitename.com/CocaCola". I've tried using the TRIM function but that doesn't work. I have tried the REPLACE function aswell but that seems not to work either. Any Solutions?
(Taken from an attempt to edit an answer:)
Update: The REPLACE and FIND Functions work but only if the string contains the amount of the desired character. And if the character doesn't appear the same amount of times the formula has asked for you will always get the string #VALUE which means it hasn't worked
SharePoint Calculated Fields use Excel functions, not .NET functions, so you probably want to use SUBSTITUTE rather than REPLACE.
Try something like this:
=SUBSTITUTE([Pitch Name], " ", "")
Update:
According to Xue-Mei Chang in Calculated Field Error:
The "SUBSTITUTE" function is not available in SharePoint.
As a workaround, he proposes:
For the "SUBSTITUTE" function, you have to use a combination of the "REPLACE" function with a "FIND" function. The "FIND" would return the position of the desired character in the string, which would then pass on to the "REPLACE" function so it can replace it with the new character.
Im just wondering if it is possible to put a variable in a pattern match in Lua. Like something similar to the following:
var = "hello"
pattern = string.match(datasource, "(var)%s(a%+)")
The reason I need to do this is because the variable "var" will change periodically. (it will be in a loop)
Cheers in advance
Lua doesn't handle string interpolation inside of the quotes. Instead, you'll need to concatenate the parts with the var as a var reference and the rest as quote strings.
"("..var..")%s(a%+)" starts with a "(" as a string literal, concatenates the variable, then finishes off the rest of the string with a string literal.
Use "("..var..")%s(a%+)" instead.
I needed the same thing I think, a variable in a pattern match, but the above solution didn't work for me. I'm posting my solution in case it helps someone, didn't find anything else on the net like it.
I read a ': ' delimited file (name: tel) and want to search by name in the file and have the name and telephone number as answer.
local FileToSearch = h:read'*a' -- Read all the file
var = io.read() -- ask the name
string.gmatch(FileToSearch, ''..var..': '..'%d+') -- search for name, concatenate with number