101 FREE REAL TECH BOOKS GIVEN AWAY EVERY MONTH! Sign up & choose your books! #101FreeTechBooks http://www.101ftb.com/S40W50T160
Recent Updates RSS Toggle Comment Threads | Keyboard Shortcuts
jmaglasang
Extracting Text Between Words(Pattern) using Regex in JavaScript
Below are the ways to extract text between words in javascript:
Given the String “Name: John Berkins Address: LA, USA”
var data = "Name: John Berkins Address: LA, USA";
//using String.indexOf + String.substring
var name = data.substring(data.indexOf("Name:")+6,data.indexOf("Address"));
var addr = data.substring(data.indexOf("Address:") + 9);
alert(name);
alert(addr);
//using Regex (with the use of Non-Capturing Group(?:)
var rname = data.match(/(?:Name:)(.+)(?:Address:)/)[1];
var raddr = data.match(/(?:Address:)(.*)/)[1];
alert(rname);
alert(raddr);
//Note: the regex code above may not work if the data contains \n (newline character)
// this is because of the (.+) expression cannot disregards \n chars,
// the workaround is to change it to anoter expression or to remove the \n char before
// the extraction process: h
//Example:
//
//data = data.replace(/\n/g,' ');
//var rname = data.match(/(?:Name:)(.+)(?:Address:)/)[1];
//var raddr = data.match(/(?:Address:)(.*)/)[1];
-
jaycverg
jmaglasang
Generating Unique Strings in Javascript
Here is a simple way to generate a unique string in javascript.
var ts = (new Date()).getTime().toString();
var url = "ajaxHandler.php?param1=value1&paramn=valuen&t=" + ts;
//do ajax call...
This method is very helpful for ajax developers, to overcome the problem of cached ajax requests in IE.
Update:
Here’s another way of creating unique strings
String.unique = String.guid = String.uid = String.uuid = function(){
var idx = [], itoh = '0123456789ABCDEF'.split('');
// Array of digits in UUID (32 digits + 4 dashes)
for (var i = 0; i < 36; i++) { idx[i] = 0xf & Math.random() * 0x10; }
// Conform to RFC 4122, section 4.4
idx[14] = 4; // version
idx[19] = (idx[19] & 0x3) | 0x8; // high bits of clock sequence
// Convert to hex chars
for (var i = 0; i < 36; i++) { idx[i] = itoh[idx[i]]; }
// Insert dashes
idx[8] = idx[13] = idx[18] = idx[23] = '-';
return idx.join('');
}
Sample Use:
var id=String.guid(); va u = String.uuid();
-
jaycverg
to match new line you can use the expression:
var rname = data.match(/(?:Name:)([\w\d\s]*)(?:Address:)/)[1];-
jaycverg
sorry, wrong post… ^____^
-
jmaglasang
Setting the Page Title in ASP NET from Server Code
Here is a quick n easy way to set the HTML Page Title from the server side, that most developers don’t know yet.
VBNET:
Me.Header.Title = "Title Here"
C#:
this.Header.Title = "Title Here";
jmaglasang
TextArea SelectedText, SelectionStart, SelectionEnd, SelStart, SelEnd (IE and FireFox)
Simple way of getting the html textarea’s selection properties selectedText, selectionStart, selectionEnd:
Javascript:
function getTextAreaSelection() {
var textArea = document.getElementById('textarea1');
if (document.selection) { //IE
var bm = document.selection.createRange().getBookmark();
var sel = textArea.createTextRange();
sel.moveToBookmark(bm);
var sleft = textArea.createTextRange();
sleft.collapse(true);
sleft.setEndPoint("EndToStart", sel);
textArea.selectionStart = sleft.text.length
textArea.selectionEnd = sleft.text.length + sel.text.length;
textArea.selectedText = sel.text;
}
else if (textArea.selectionStart){ //FF
textArea.selectedText = textArea.substring(textArea.selectionStart,textArea.selectionEnd);
}
alert("Selection Start==> " + textArea.selectionStart + "\n" +
"Selection End ==> " + textArea.selectionEnd + "\n" +
"Selected Text ==> " + textArea.selectedText + "\n" +
"TextArea Value ==> " + textArea.value);
}
HTML:
<textarea id="textarea1"></textarea> <button onclick="getTextAreaSelection()">Get Selection Info</button>
-
Jim
What if the selected text is repeated within the content?
“textArea.value.indexOf” will return the first instance of the selected text, but that may not be the text that is actually selected, they are just the same because they are repeated.
For example: “My name is Fred, and his name is John.”
If I select the second instance of “name is”, when I run your function I will get the first. This isn’t a problem if you just want to know the text that is selected, but it is if you want to manipulate it.
-
jmaglasang
You have a point there them, I have update the code but there is still a little problem, it cannot return the correct caret position in IE.
-
jaycverg
IE gives us extra work to do w/ these things…
( -
Shaun
I know I’m a little out of date, but I found this helpful, but noticed a few things.
I’m getting my page to work in FF first, then I’m trying IE, but you can’t call substring of an HTML element, you have to call substring on it’s value instead.
As for manipulating the data;
selectedText = textArea.value.substring(textArea.selectionStart,textArea.selectionEnd);
will return the value, however, if you want to manipulate it, you’ll want to add 2 more variables:
part1 = textArea.value.substring(0,textArea.selectionStart);
part2 = textArea.value.substring(textArea.selectionEnd,textArea.textLength);
And use standard string addition… depending on what you want to do with it of course.
jmaglasang
Generating Unique Strings in NET
Approach 1:
String s1 = Guid.NewGuid().ToString();
String s2 = Guid.NewGuid().Tostring("N");
String s3 = Guid.NewGuid().ToString("P");
String s3 = Guid.NewGuid().ToString("D");
[code]
Approach 2:
[code]
String s1 = System.IO.Path.GetRandomeFileName();
String s2 = System.IO.Path.ChangeExtension(System.IO.Path.GetRandomFileName(),null);
Comparison or the 2 Approaches:
1. Approach1 generates at least 32 characters (0-9 and a-f) letters only.
Hint: larger size on the database, absolutely unique.
2. Approach2 Generates at least 8 characters (0-9 and a-z) letters.
Hint: Good for Captcha, less size on the database, might have duplicates
jmaglasang
Reversing Flash Timeline
Just recently, I have encountered a really simple problem that I have hard time figuring out the solution, but in hours of looking for that solution I just found one.
In the web, if we search for reversing a timeline in flash, we will find mostly solutions that are done using another movie clip, but It doesn’t solve my problem. I only need to reverse the timeline without creating another movie clip.
Here’s how I figure it out. The solution that worked for me, is to use the setInterval and the clearInterval.
To do so, create a simple animation/tween, then on the last frame, insert the following action script:
stop();
var speed:Number = 40;
function goto(destination) {
if (_root._currentframe == destination)
clearInterval(nIntervals);
else
prevFrame();
}
var nIntervals = setInterval(goto, speed,15);
In this, example I assumed you have more than 15 frames in your animation, let say you have 60-frame animation, From frame 60 the timeline will reverse play until frame 15.
-
sepehr
hi , it’s very useful to me .thanks.
jmaglasang
Flash Disk Virus Cleaner
I just found this tool in the web and find it useful, save it with .bat extension then execute. It helps a lot.
@ECHO OFF cls echo Zabyer Flash Disk Virus Cleaner v1.0.3 echo http://www.zabyer.org echo Last Updated: October 14, 2007 8:06am echo --------------------------------- echo Files that will be deleted: echo imgkulot, INFO.exe, Desktop.ini, scvhosts.exe echo TTM*.vbs, krag.exe, sysdll.exe, RavMon.exe, msv*.dll echo and other flash disk pest!!! echo --------------------------------- echo Resetting Stupid Virus attributes... echo (Disarming flash disk pest!) attrib -r -h -s -a autorun.* attrib -r -h -s -a TTM*.* attrib -r -h -s -a imgkulot*.* attrib -r -h -s -a RECYCLER\INFO.exe attrib -r -h -s -a RECYCLER\Desktop.ini attrib -r -h -s -a sysdll.exe attrib -r -h -s -a krag.exe attrib -r -h -s -a RavMon*.* attrib -r -h -s -a msv*.dll attrib -r -h -s -a scvhosts.exe attrib -r -h -s -a svhost.exe attrib -r -h -s -a C:\Windows\svhost.exe attrib -r -h -s -a C:\Windows\svhost32.exe attrib -r -h -s -a "New Folder".exe echo --------------------------------- echo Attributes Reset! echo Preparing Clean-Up Procedures... echo Next step is to delete all the pest. echo --------------------------------- pause echo --------------------------------- echo Deleting Stupid Virus... echo --------------------------------- del autorun.* del TTM*.* del imgkulot*.* del RECYCLER\INFO.exe del RECYCLER\Desktop.ini del sysdll.exe del krag.exe del RavMon*.* del msv*.dll del scvhosts.exe del svhost.exe del C:\Windows\svhost.exe del C:\Windows\svhost32.exe del "New Folder".exe echo --------------------------------- echo Flash Disk Cleaned-Up! echo --------------------------------- echo Please report for new virus so that this Virus Cleaner will be updated. :) echo Send to admin@zabyer.org or camilord@zabyer.org you feedbacks... echo --------------------------------- pause
-
wilma simplicity!
unsaon mana pagamit sir?
-
cica
thanks a lot…
-
kevin smith
My computer is running very slow. Has been acting crazy for a week in a half. Thanks
-
camilord
I just found this URL in google search results during my search for common USB virus. I remember this batch file script I created last year 2005 and continued updating.
Lately, I was affected with another kind of malware. so i decided to improve this batch file to a better one.
Introducing Flash Disk Cleaner v1.0.15.29!
Download at http://www.kagayan.com/index.php?option=software&task=view&q=Flash_Disk_Cleaner&id=1
Enjoy my new creation! hehehehehee..
-
jmaglasang
@camilord, thanks for update
-
endalkachew
plise cline the flashe disc
-
-
His_wife10
Question: When exactly was the Flash indexing algorithm implemented? ,
-
Maxx47
Second, fans do not always get the stars they want. ,
-
Anonymous
I NEED YOUR HELP
jmaglasang
Step-by-step Creation of Executable Jar for Java
1. Start Command Prompt. 2. Navigate to the folder that holds your class files: C:\>cd\ C:\>cd java-code 3. Set path to include JDK’s bin. For example: C:\java-code> SET PATH=%PATH%:c:\Program Files\Java\jdk1.5.0\bin 4. Compile your class(es): C:\java-code> javac TestForm.java C:\java-code> javac Main.java 5. Create a manifest file: C:\java-code> echo Main-Class: Main >manifest.txt 6. Create a jar file: C:\java-code> jar cvfm welcome.jar manifest.txt Main.class TestForm.class 7. Test your welcome.jar: C:\java-code> welcome.jar
And that’s it we’re done.
-
Belfry
Sir,,
sir..plss dili gyud cya mogana ang jar… error: could not find the main class.Program will exit
sir tabang…sir plsss kani na lang gyud pag jar …
-
Agustin
Sir,,
Unsa diay possible cause y pagjar namu kay ni error.. ingon “could not find the main class. Program will exit.”
libug jud sir…
la me kabalo unsa sunod buhaton -
Joy
Sir,unsaon pagpadisplay sa xml data sa jtable? plz. reply…asap.. mao na kng jud na amo kulang sir… plz..
help us…..
to match new line you can use the expression:
var rname = data.match(/(?:Name:)([\w\d\s]*)(?:Address:)/)[1];