AngularJS Not counting newlines in var length - angularjs

When I enter some text and then enter some new lines using test.length does not count new lines in the string. I'm using this text to send SMS messages which are sensitive to all newlines so it all has to count. Any ideas?
Hit enter 4 times and see the counter doesn't go up.
http://codepen.io/clouddueling/pen/HJAfn

You need an ng-trim="false" to avoid automatic trimming: http://codepen.io/musically_ut/pen/KHBto
The documentation for this is missing but there is an pull request on the way.

The control characters for CRLF (\r\n) typically don't count in the length of a string. You can detect them with a matching regex and use the number of matches to increment your character count. Something like this:
var crlfCount = mytext.match(/[\n\r]|[\r\n]/g);
linecount += crlfCount.length;

Related

fetch a discord link from a long text

૮₍ • ᴥ • ₎ა・Raiden ▬▭⋱𓂅
ᘏ⑅ᘏ╭╯Welcome╰╮𓂃ᘏᗢ
・・・・・・・・・・・・・・・・・・・・・
https://discord.gg/rsCC8y7WC4
・・・・・・・・・・・・・・・・・・・・・
Join!
・・・・・・・・・・・・・・・・・・・・・
How can I pull the "discord.gg/rsCC8y7WC4" link from a text like this
console.log(invitelink) ==> discord.gg/rsCC8y7WC4
Use String.match() for this. String.match accepts a regex argument which looks like this:
let str = 'hey there this is just a random string';
let res = str.match(/random/);
//res is now ['random']
Now for your problem, you are probably looking for this:
if(msg.content.match(/discord\.gg\/.+/) || msg.content.match(/discordapp\.com\/invite\/.+/)) return msg.channel.send('Hey! You put an invite in your message!');
Now that regex may look a bit messy/complicated but the \s are to escape the character and make sure regex knows that it’s not the special character it uses, and is actually just a character part of the search. To clarify why the above example should work, here’s a little explanation:
match() returns either an array (if it gets a match) or null (if it gets no match). You are searching for the strings 'discord.gg/' followed by any characters and also checking for the string 'discordapp.com/invite/' also followed by any characters.
If this doesn’t work, please tell me.

VBSCRIPT REPLACE not removing spaces from Decrypted fields

Got quite a head-scratcher....
I'm using the VBScript function REPLACE to replace spaces in a decrypted field from a MSSQL DB with "/".
But the REPLACE function isn't "seeing" the spaces.
For example, if I run any one of the following, where the decrypted value of the field "ITF_U_ClientName_Denc" is "Johnny Carson":
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/")
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/")
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"),"Chr(160)","/")
REPLACE(CSTR(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"))," ","/")
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/",1,-1,1)
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/",1,-1,0)
The returned value is "Johnny Carson" (space not replaced with /)
The issue seems to be exclusively with spaces, because when I run this:
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"),"a","/")
I get "Johnny C/rson".
Also, the issue seems to be exclusively with spaces in the decrypted value, because when I run this:
REPLACE("Johnny Carson"," ","/")
Of course, the returned value is "Johnny/Carson".
I have checked what is being written to the source of the page and it is simply "Johnny Carson" with no encoding or special characters.
I have also tried the SPLIT function to see if it would "see" the space, but it doesn't.
Finally, thanks to a helpful comment, I tried VBS REGEX searching for \s.
Set regExp = New RegExp
regExp.IgnoreCase = True
regExp.Global = True
regExp.Pattern = "\s" 'Add here every character you don't consider as special character
strProcessed = regExp.Replace(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"), "?")
Unfortunately, strProcessed retruns "Johnny Carson" (ie. spaces not detected/removed).
If I replace regExp.Pattern = "a", strProcessed returns "Johnny C?rson".
Many thanks for your help!!
As we found, the right character code is 160, and that did the trick:
replace(..., ChrW(160), "...")
This seems to be data specific and, additionally, as an alternative you can try to get same encoding of the source script (i.e. save with Save As with Encoding), or convert received database value into a different target encoding.

how to write script on validating number from the text? for ex: i like to get numeric value "2" from field "Staus(2)"

On Selenium, I'm writing script to get the number from the text. suppose there is a field 'Status(2)'. The number in the brackets keep changing. I want to get the value.
This code should get back the text for the element you have provided:
WebElement web_element_found = driver.findElement(By.id("ctl00_ctl00_cphBMain_cphMain_lblObjects"));
String element_text = web_element_found.getText();
Then you can have a look at this answer for how to use regex to extract the digit from the string: Regex to extract digit from string in Java
Hope this helps!
Here is the solution.
String rawText = driver.findElement(By.id("ctl00_ctl00_cphBMain_cphMain_lblObjects")).getText();
String number = rawText.substring(s.indexOf("(") + 1).substring(0, s.indexOf(")"));
System.out.println(number);

limit textarea entry without maxlength attribute in angularjs

I have a requirement where the user can enter/copy-paste 25 ids separated by comma in a textarea ; there is no maximum size for the ids.Thereafter he cannot enter any characters.He then submits those ids for search.
Is there any way to limit the id number to 25 and then not allowing the user to enter anything.
I cannot use maxlength here.Also all these checking have to happen before user submits and the control reaches the angularjs controller.
I am using angularjs,HTML5,CSS3,bootstrap.
Basically what you'd need to is count the number of commas in the string and raise an error when it exceeds 24. You could do this using ng-onchange or when the user submits. This answer: Count the number of occurrences of a character in a string in Javascript should help you with counting the commas.
You can split the model of the input on ng-change like this for example ( where textareaValue is the model of the textarea ):
var textareaValueArray = textareaValue.split(',');
if( textareaValueArray.length > 25 )
textareaValue = textareaValueArray.slice(0,25).join(',')

how to write formatted text into a file

I was trying to write to a file from textbox input with date:
Here is a part of the code:
DateTime dt=System::DateTime::Now;
System::IO::StreamWriter^ history = gcnew StreamWriter("history.txt");
history->WriteLine(textBox1->Text);
history->WriteLine(dt);
history->Close();
But the output is like this: text
09/02/2015 23:26:07
But I want it to be like:
text 09/02/2015 23:26:07
And also has to append next input to next line of the file.
It's something like a log file.
you use two writeLine and so that write it in 2 Line concat them to write it in one line
history->WriteLine(textBox1->Text);
history->WriteLine(dt);
change this part to
history->write(textBox1->Text);
history->writeLine(dt);
history->WriteLine(textBox1->Text);
Using WriteLine() causes the line break of course. You'd have to use Write() instead. And fret a bit about how you get the extra space between the text and the date, never hesitate to use composite formatting in .NET:
history->WriteLine("{0} {1}", textBox1->Text, System::DateTime::Now);

Resources