Monday, June 3, 2024
45
rated 0 times [  47] [ 2]  / answers: 1 / hits: 26560  / 11 Years ago, thu, october 31, 2013, 12:00:00

In my script I have a string with newline characters. Using newline (n)character I parsed it to array.



I struggling to compare in my if condition (parsedarray[0]=='newline character'). Please help me to compare the newline character in my if condition. I also tried to alert the parsedarray[0]. It alerts blank alert box.` I am unable to check the newline character in if statement. For instance, I have a single String with multiple newline , tabs consisting of 40 lines. In my script user enter a line number, string for that line number, after receiving both information, I want to replace the newline with entered string in the line number. Here line number is an index. So that again I will construct a single string by joining the parsed string. Also my array size should not grow. or Reduce.??? And importantly I want to validate the given String with the available string, if both matches (other than newline) need to put alert message.



 var strarray=doc.getElementbyid('mytextarea').value;
var parsedarray=[];
parsedarray=strarray.split('\n');`

More From » if-statement

 Answers
13

Instead of split use indexOf to find position of the first occurrence of a specified value in a string.



Eg:



var text=Hello worldn;
if(text.indexOf(n)==-1){
alert(No newline characters)
}else{
alert(Contains newline characters)
}

[#74591] Wednesday, October 30, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cameron

Total Points: 591
Total Questions: 112
Total Answers: 88

Location: Botswana
Member since Sat, Jan 7, 2023
1 Year ago
cameron questions
;