Reputation: 139
this does not makes sense, how to remove the specific chars from the string?
Code bellow don't work
Thanks
var CamlQuer = "{"$o_1":true,"$N_1":"<View><ViewFields><FieldRef Name=\"Title\" /><FieldRef Name=\"Date1\" /></ViewFields><Joins><Join Type=\"LEFT\" ListAlias=\"Workshop\"><Eq><FieldRef Name=\"WorkshopResult\" RefType=\"ID\" /><FieldRef Name=\"ID\" List=\"Workshop\" /></Eq></Join></Joins><ProjectedFields><Field ShowField=\"Workshop\" Type=\"Lookup\" Name=\"Title\" List=\"Workshop\" /></ProjectedFields><Query><Where /></Query></View>"}"
camlQuer.split('"$o_1":true,"$N_1":"').join('');
console.log(camlQuer);
Upvotes: 2
Views: 2227
Reputation: 139
My approach in order to "escape" the string
let regexp = new RegExp(camlQuer);
Using Nick solution
let regexp = new RegExp(camlQuer);
console.log(camlQuer);
camlQuer = camlQuer.replace('"$o_1":true,"$N_1":"', '');
Upvotes: 0
Reputation: 11968
Looks like part of the problem is your CamlQuer
needs additional escapes and to match the casing of camlQuer
below.
Next, the split
method does not modify the variable directly, so you need to reassign the output.
These change would make your code look like:
var camlQuer = "{\"$o_1\":true,\"$N_1\":\"<View><ViewFields><FieldRef Name=\"Title\" /><FieldRef Name=\"Date1\" /></ViewFields><Joins><Join Type=\"LEFT\" ListAlias=\"Workshop\"><Eq><FieldRef Name=\"WorkshopResult\" RefType=\"ID\" /><FieldRef Name=\"ID\" List=\"Workshop\" /></Eq></Join></Joins><ProjectedFields><Field ShowField=\"Workshop\" Type=\"Lookup\" Name=\"Title\" List=\"Workshop\" /></ProjectedFields><Query><Where /></Query></View>\"}"
camlQuer = camlQuer.split('"$o_1":true,"$N_1":"').join('');
console.log(camlQuer)
However, you would be better off using the replace
method which is meant to remove or replace a string of characters. Your code would then look like:
var camlQuer = "{\"$o_1\":true,\"$N_1\":\"<View><ViewFields><FieldRef Name=\"Title\" /><FieldRef Name=\"Date1\" /></ViewFields><Joins><Join Type=\"LEFT\" ListAlias=\"Workshop\"><Eq><FieldRef Name=\"WorkshopResult\" RefType=\"ID\" /><FieldRef Name=\"ID\" List=\"Workshop\" /></Eq></Join></Joins><ProjectedFields><Field ShowField=\"Workshop\" Type=\"Lookup\" Name=\"Title\" List=\"Workshop\" /></ProjectedFields><Query><Where /></Query></View>\"}"
camlQuer = camlQuer.replace('"$o_1":true,"$N_1":"', '');
console.log(camlQuer)
Upvotes: 2