Giving the string below with "server type" separated by comma:
string serverTypeList = "DB, IIS, CMDB";
//server.Type in the loop below should have value of "MDB"
My problem is that in this scenario it will return TRUE because "MDB" string is inside the serverTypeList.
I need it to return TRUE only if it matches a type of "MDB" and not "CMDB":
...
from site in SiteManager.Sites
from server in site.Servers
where
serverTypeList.Contains(server.Type)
select new Server()
{ ID=server.ID, SiteName=site.Name }
...
How can I change the code above?
Thank you
(", " + serverTypeList + ", ").Contains(", " + server.Type + ", ")
is one standard way to handle this. I'm not clear on the language you're using, so I don't know the exact syntax you would need, but the general idea is to ensure that the term appears between delimiters by forcing delimiters before and after the list string.
Related
I'm working with the following Azure Logic App expression (Workflow Definition Language (WDL)):
formatDateTime(
utcNow(),
'MM'
)
The WDL docs say that the formatDateTime function should return with a string value.
This is what I'm seeing...
...EXCEPT, the resulting string is impervious to further string manipulation in WDL!
Example:
To get rid of the leading space in " 02":
trim (trim(formatDateTime(utcNow(),'MM'))) ...OR
replace (replace(formatDateTime(utcNow(),'MM'), ' ', '')) should work
But neither of these work, the resulting " 02" remains as an untrimmed string
Similar with int (int(trim(formatDateTime(utcNow(),'MM')))).
The result is not an int, but rather the same " 02" string!
Is this a WDL bug?
Likely contributing this issue as well.
Very new to SQL so I appreciate your patience in advance.
I have a column in a table that stores a particular set of instructions; each instruction is encapsulated by a carriage return.
eg: char(13)+ #instruction1 + char(13)...
#Instruction1 is a string of variable length but I do know a certain part of the string eg: #instruction1 = some string + #knownstring + some string.
So we have char(13) + (some string + #knownstring + some string) +char(13).
I want to replace this entire line with ''.
Identifying it just using the #knownstring.
Is this possible?
Thanking you all again, I really appreciate your assistance
select replace(replace(column,#knownsting,''),char(13),'')
from table
where key=1235
Replaces only the #knownstring but I also need to replace the surrounding text between the two char(13)
You might try something along this:
DECLARE #KnownString VARCHAR(50)='Keep This'
DECLARE #YourString VARCHAR(MAX)='blah' + CHAR(13) + 'dummy keep this dummy more' + CHAR(13) + 'Something without the known part' + CHAR(13) + 'Again with Keep THIS';
SELECT STUFF(
(
SELECT CHAR(13) + CASE WHEN CHARINDEX(#KnownString,LineText)>0 THEN #KnownString ELSE LineText END
FROM (SELECT CAST('<x>' + REPLACE(#YourString,CHAR(13),'</x><x>') + '</x>' AS XML)) A(Casted)
CROSS APPLY Casted.nodes('/x') B(fragment)
OUTER APPLY (SELECT fragment.value('text()[1]','nvarchar(max)')) C(LineText)
FOR XML PATH(''),TYPE
).value('.','nvarchar(max)'),1,1,'');
The result
blah
Keep This
Something without the known part
Keep This
The idea
The string is transformed to XML by replacing the line breaks with XML tags. Now we can query all text lines separately, check them for the known string, do the needed manipulation, and finally reconcatenate all fragments using the XML-trick (together with STUFF to get rid of the leading CHAR(13)).
Remarks
Using v2016 I'd use the split-string approach with OPENJSON and starting with v2017 there is STRING_AGG() to make the reconcatenation easier.
I have an object being passed to the controller from a view and it contained double spaces in it that I need to remove. I have gone down the standard path and used the correct functionality to try and remove these double spaces but it doesn’t work. The string did also have a space at the from and then end that I managed to remove with .trim().
Below is what I used to try and Replace all the double spaces:
object = params.objectValue.trim()
object.replaceAll(" ", " ")
This did not work and still had the spaces so I tried this:
newObj = ""
object = params.objectValue.trim()
newObj = object
newObj.toString().replace(" ", " ")
here is an example of the string text:
"the person drove the car on 21/12/04 at 12:00"
This didn’t work either, has anyone got any idea as i dont really understand what i can do to remove these double spaces?
Thanks in advance
replaceAll() doesn't mutate the original string, it returns a new string with the replaced elements. You need to reassign params.objectValue to the result of replaceAll()
params.objectValue = params.objectValue.replaceAll(" ", " ").trim()
I want to test if a CKEditor ( Rich Text ) field is empty as part of some business logic.
I do not want to use the built in validation features.
If a CK Editor field has previously had text and then this text is deleted there is still content e.g.
<p dir="ltr">
</p>
I can get a handle to this text string using :
dataVar = xspdoc.getDocument().getMIMEEntity(dataNamevar).getContentAsText();
Is there a way to test if the CKEditor field is empty of visible text ?
Technically speaking, if it has what amounts to a a single visible newline in it as you've shown in your question, it isn't really "empty".
Realistically, you'll have to parse the content value to find out if there is content that is not either inside tags or the few special characters like and so on.
I tend to do this in js, if I have to, by taking the whole string of text and splitting it into an array based on "<" then taking each element of the array and removing an text to the left of an ">", then trim. That leaves me an array of either empty strings or text that is outside any tags. From there it's easy enough check for any of strings in the array to see if they are not empty, and not " ".
This may be more cumbersome then some built in parser that I don't know, but it's fairly reliable and quick. (and a very similar method can be used in formula language as well).
In ssjs formula you could:
var checkString = #trim(#replacesubstring(#implode( #trim (#right( #explode( sourceHTMLstring , "<" ) , ">" ) ) , " "), " " , ""));
if(checkstring == "") {
// *** You have no content
} else {
// *** you have content
}
Obviously this could be done just as easily in pure javascript, but the old formula language is so ingrained in my head, I'd go this way just out of habit.
** Also note: You may want to check for an <img> tag in there somewhere in case someone has done absolutely nothing other than put an image in the rich text.
CKEditor has its own API, I guess this is the right method to use:
http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#getData
This might be helpful: http://xpagetips.blogspot.com/2011/10/be-careful-with-empty-ckeditor-rich.html
Check if CKEditor is empty
For any browser
var editor=CKEDITOR.instances.editorName.getData();
I found best answer for this
function validateCKEDITORforBlank(ckData)
{
ckData = ckData.replace(/<[^>]*>|\s/g, '');
var vArray = new Array();
vArray = ckData.split(" ");
var vFlag = 0;
for(var i=0;i<vArray.length;i++)
{
if(vArray[i] == '' || vArray[i] == "")
{
continue;
}
else
{
vFlag = 1;
break;
}
}
if(vFlag == 0)
{
return true;
}
else
{
return false;
}
}
Link
I want to match a few lines for a string and a few numbers.
The lines can look like
" Code : 75.570 "
or
" ..dll : 13.559 1"
or
" ..node : 4.435 1.833 5461"
or
" ..NavRegions : 0.000 "
I want something like
local name, numberLeft, numberCenter, numberRight = line:match("regex");
But I'm very new to the string matching.
This pattern will work for every case:
%s*([%w%.]+)%s*:%s*([%d%.]+)%s*([%d%.]*)%s*([%d%.]*)
Short explanation: [] makes a set of characters (for example the decimals). The last to numbers use [set]* so an empty match is valid too. This way the number that haven't been found will effectively be assigned nil.
Note the difference between using + - * in patterns. More about patterns in the Lua reference.
This will match any combination of dots and decimals, so it might be useful to try and convert it to a number with tonumber() afterwards.
Some test code:
s={
" Code : 75.570 ",
" ..dll : 13.559 1",
" ..node : 4.435 1.833 5461",
" ..NavRegions : 0.000 "
}
for k,v in pairs(s) do
print(v:match('%s*([%w%.]+)%s*:%s*([%d%.]+)%s*([%d%.]*)%s*([%d%.]*)'))
end
Here is a starting point:
s=" ..dll : 13.559 1"
for w in s:gmatch("%S+") do
print(w)
end
You may save these words in a table instead of printing, of course. And skip the second word.
#Ihf Thank you, I now have a working solution.
local moduleInfo, name = {};
for word in line:gmatch("%S+") do
if (word~=":") then
word = word:gsub(":", "");
local number = tonumber(word);
if (number) then
moduleInfo[#moduleInfo+1] = number;
else
if (name) then
name = name.." "..word:gsub("%$", "");
else
name = word:gsub("%$", "");
end
end
end
end
#jpjacobs Really nice, thanks too. I'll rewrite my code for synthetic reasons ;-) I'll implement your regex of course.
I have no understanding of the Lua language, so I won't help you there.
But in Java this regex should match your input
"([a-z]*)\\s+:\\s+([\\.\\d]*)?\\s+([\\.\\d]*)?\\s+([\\.\\d]*)?"
You have to test each group to know if there is data left, center, right
Having a look at Lua, it could look like this. No guarantee, I did not see how to escape . (dot) which has a special meaning and also not if ? is usable in Lua.
"([a-z]*)%s+:%s+([%.%d]*)?%s+([%.%d]*)?%s+([%.%d]*)?"