I need to read a String character by character. i.e, If I have a string like CILD, then I have to read it as C and then I and so on.
I tried this with regex and also with properties, but nothing has worked out.
Please let me know a solution for the same.
thanks.
You can use the below snippet in your code to add a _ at end of every character
propertyregex property="propB" input="${input}" regexp="" replace="_" global="true"
And then split the property with dleimiter as "_".
for list="${propB}" delimiter="_" param="split"
Cheers.
Note : This worked out very well for me.
Related
Please help me in extracting the string from this text like
id1:value1,id2:value2
id1:value1a,id2:value2a
from
"[{id1:value1,id2:value2},{id1:value1a,id2:value2a}]"
{([^}]+)} will find and capture anything that is inside { }
You should include more detail in your question though and show that you have made an attempt at it yourself.
Working codes
unlist(regmatches(text, gregexpr("\\{.*?\\}", text)))
unlist(regmatches(text, gregexpr("\\{([^}]+)\\}", text)))
I need to use the .replace() function to replace abc123="NULL" with abc123=NULL but only when NULL is the only word between the quotation marks, otherwise, leave it as it is.
Struggling to find the correct combination of escpaped characters to make this work.
Note: there are no quotation marks at the beginning or end of this data value i.e. it is not abc123="NULL" that I am working with. It is explicitly abc123="NULL"
Can any one manage this?
Edit: I'm using a privately written development environment that builds using Java.
Edit: If I could it would look like this x.replace(="NULL", =NULL) BUT I need to escape the = and quotation marks. Baring in mind I can only do this replacement if the word is NULL and is not any other word.
Not sure to well understand but, is that what you want:
var x = 'abc="NULL"';
x = x.replace('="NULL"', '=NULL');
console.log(x);
This I probably a dumb question but it beats me.
The same thing in Python works perfectly, although in AS3 doesn't.
var s:String = "123456";
trace(s.split(/../gm));
Expecting this as array: ['12','34','56']
But instead I get: [,,]
I have experimented various regexr patterns but none split into 2-char batches.
Any ideas / solutions ?
You're using the split command, which means the string will be divided into an array of values using the regular expression .. to match the delimiters. These delimiters are then not included in the output.
I think you want to do something like s.match(/../g). See also this link for more information about .match
I need a little help with my calculator program. I have created the code for the main buttons like the numbers 0-9 and the arithmetic operators to make it perform simple calculations.
What I'm having problems with right now is making the CE button work, after clicking the CE button I need the last entered character to be removed from the display label.
I have tried to adapt this code somehow, but it doesn't work:
lblResult->substr(0, lblResult->size()-1);
I know I'm doing somehting wrong here, can you please help me?
Thanks in advance
...Now that we know that lblResult is a System.Windows.Forms.Label, we can look at the documentation.
A Label has a Text Property, which is a String^ (i.e. a string reference).
For what you want to do, the Remove Method of String is appropriate. But note in the documentation it says that it "Returns a new string in which a specified number of characters from the current string are deleted." This means that it does not modify the string, but returns a modified copy.
So to change the label's text, we need to assign to its Text property what we want: the current string with all of the characters except the last:
lblResult->Text = lblResult->Text->Remove(lblResult->Text->Length - 1);
lblResult->resize(lblResult->size() - 1);
In this case you can use components Remove and Length methods.
Use the following code to access the components text:
component->Text
Than remove the last character of string by accessing Remove and component Length method
= component->Text->Remove(component->Text->Length - 1)
I hope you find this useful.
Just asking the obvious -- the whole statement is
*lblResult = lblResult->substr(0, lblResult->size()-1);
right?
I have a txt file with content
$NETS
P3V3_AUX_LGATE; PQ6.8 PU37.2
U335_PIN1; R3328.1 U335.1
$END
need to be updated in this format, and save back to another txt file
$NETS
'P3V3_AUX_LGATE'; PQ6.8 PU37.2
'U335_PIN1'; R3328.1 U335.1
$END
NOTE: number of lines may go up to 10,000 lines
My current solution is to read the txt file line by line, detect the presence of the ";" and newline character and do the changes.
Right now i have a variable that holds ALL the lines, is there other way something like Replace via RegEx to do the changes without looping thru each line, this way i can readily print the result
and follow up question, which one is more efficient?
Try
ResultString = Regex.Replace(SubjectString, "^([^;\r\n]+);", "'$1';", RegexOptions.Multiline)
on your multiline string.
This will find any string (length one or more) at the start of a line up until the first semicolon if there is one and replace it with its quoted equivalent.
It should be more efficient than looping through the string line by line as you're doing now, but if you're in doubt, you'd have to profile it.
You could probably find all the matches using something like \w+; but I don't know how you'd be able to do a replace on that using Regex.Replace to add the 's but keep the original match.
However, if you already have it as one variable, you don't have to read the file again, either you could make your code find all ;s and then find the previous newline for each, or you could use a String.Split on newlines to split the variable you've already got into lines.
And if you want to get it back to one variable you can just use String.Join.
Personally I'd normally use the String.Split (and possibly the String.Join if needed) method, since I think that would make the code easy to read.
I would say Yes! this can be done with Regular expressions. Make sure you got the "multiline" option turned on and craft your regular expression using some capture groups to ease the work.
I can however say this will NOT be the optimal one. Since you mention the amount of lines you could be processing, it seems 'resource wise' smarter to use a streaming approach instead of the in memory approach.
Taking the Regex approach (and this took 15 mins so please don't think this is an optimal solution, just prove it would work)
private static Regex matcher = new Regex(#"^\$NETS\r\n(?<entrytitle>.[^;]*);\s*(?<entryrest>.*)\r\n(?<entrytitle2>.[^;]*);\s*(?<entryrest2>.*)\r\n\$END\r\n", RegexOptions.Compiled | RegexOptions.Multiline);
static void Main(string[] args)
{
string newString = matcher.Replace(ExampleFileContent, new MatchEvaluator(evaluator));
}
static string evaluator(Match m)
{
return String.Format("$NETS\r\n'{0}'; {1}\r\n'{2}'; {3}\r\n$END\r\n",
m.Groups["entrytitle"].Value,
m.Groups["entryrest"].Value,
m.Groups["entrytitle2"].Value,
m.Groups["entryrest2"].Value);
}
Hope this helps,