473,327 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

write part of a string ?


How do I write part of a string up to a certain character,
or get it in to a variable.

TIA

--

find clausen
www.photopress.dk
Jul 20 '05 #1
10 3130
find clausen <> writes:
How do I write part of a string up to a certain character,
or get it in to a variable.


I am not sure exactly what you want to do.

Do you want to change the contents of a string (up to a point)? In
that case, you can't. Javascript strings are immutable. You have to create
a new string, e.g.:

str = "dummy string";
str = "new prefix "+str.substring(6);
alert(str); // alerts "new prefix string"

Get it into a variable? I can't guess that one.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
In article <ll**********@hotpop.com>, lr*@hotpop.com enlightened us
with...

Get it into a variable? I can't guess that one.


Sure you can. :)

str="new prefix";
myNewVar = str.substring(4);

myNewVar is now "prefix".
-------------------------------------------------
~kaeli~
All I ask for is the chance to prove that money
cannot make me happy.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #3
On 02 Oct 2003 13:43:36 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
Get it into a variable? I can't guess that one.


:-)

I have this:
fv = document.title.substr(0,20)

But I want to find @ in document.title
And put that part of the string in fv

--

find clausen
www.photopress.dk
Jul 20 '05 #4
In article <t9********************************@4ax.com>, find clausen <>
enlightened us with...
I have this:
fv = document.title.substr(0,20)

But I want to find @ in document.title
And put that part of the string in fv


Which part of the string? The part from 0 to '@' or the part from '@' to
the end?
Inclusive or exclusive of the '@'?

--
-------------------------------------------------
~kaeli~
All I ask for is the chance to prove that money
cannot make me happy.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #5
Use the subtr method:

<SCRIPT LANGUAGE="JavaScript1.2">
str = "abcdefghij"
document.writeln("(1,2): ", str.substr(1,2))
document.writeln("(-2,2): ", str.substr(-2,2))
document.writeln("(1): ", str.substr(1))
document.writeln("(-20, 2): ", str.substr(1,20))
document.writeln("(20, 2): ", str.substr(20,2))
</SCRIPT>

This script displays:

(1,2): bc
(-2,2): ij
(1): bcdefghij
(-20, 2): bcdefghij
(20, 2):

More info at:
http://devedge.netscape.com/library/...g.html#1194618

-Wagner

find clausen <> wrote in message news:<ul********************************@4ax.com>. ..
How do I write part of a string up to a certain character,
or get it in to a variable.

TIA

Jul 20 '05 #6
On Thu, 2 Oct 2003 09:38:46 -0500, kaeli
<in********************@NOSPAMatt.net> wrote:
Which part of the string? The part from 0 to '@' or the part from '@' to
the end?
Inclusive or exclusive of the '@'?


from 0 to @ -1

--

find clausen
www.photopress.dk
Jul 20 '05 #7
In article <ao********************************@4ax.com>, find clausen <>
enlightened us with...
On Thu, 2 Oct 2003 09:38:46 -0500, kaeli
<in********************@NOSPAMatt.net> wrote:
Which part of the string? The part from 0 to '@' or the part from '@' to
the end?
Inclusive or exclusive of the '@'?


from 0 to @ -1


fv = document.title.substring(0,document.title.indexOf( "@"))

Note on substr/substring: substr() has two arguments - the start and the
length. substring() has two arguments - the start and the end.
-------------------------------------------------
~kaeli~
All I ask for is the chance to prove that money
cannot make me happy.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #8
On Thu, 2 Oct 2003 12:51:08 -0500, kaeli
<in********************@NOSPAMatt.net> wrote:
fv = document.title.substring(0,document.title.indexOf( "@"))

Note on substr/substring: substr() has two arguments - the start and the
length. substring() has two arguments - the start and the end.
That works perfect, thanx !

Then I will not pay you : All I ask for is the chance to prove that money
cannot make me happy.

;-)
--

find clausen
www.photopress.dk
Jul 20 '05 #9
On 2 Oct 2003 10:15:47 -0700, wa****@yahoo.com (W d'Anjos) wrote:
Use the subtr method:

<SCRIPT LANGUAGE="JavaScript1.2">
str = "abcdefghij"
document.writeln("(1,2): ", str.substr(1,2))
document.writeln("(-2,2): ", str.substr(-2,2))
document.writeln("(1): ", str.substr(1))
document.writeln("(-20, 2): ", str.substr(1,20))
document.writeln("(20, 2): ", str.substr(20,2))
</SCRIPT>

This script displays:

(1,2): bc
(-2,2): ij
(1): bcdefghij
(-20, 2): bcdefghij
(20, 2):


Thanx, I will save this !

--

find clausen
www.photopress.dk
Jul 20 '05 #10
JRS: In article <ul********************************@4ax.com>, seen in
news:comp.lang.javascript, find clausen <?@?.?> posted at Thu, 2 Oct
2003 10:36:10 :-

How do I write part of a string up to a certain character,
or get it in to a variable.


Let the character be #, and the string example be S = 'abcd#xyz'

S.replace(/#.*/, '') // -> 'abcd'
S.replace(/.*#/, '') // -> 'xyz'

OK = /(.*)#(.*)/.test(S)
// RegExp.$1 = 'abcd'
// RegExp.$2 = 'xyz'

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: brian | last post by:
how does document.write interpret "" and '' (double quotes and single quotes) what is the significance of &Url (does it signify the current url) colon : is it represented as %3A ? and...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
1
by: Daniel | last post by:
Is there any way for System.IO.StreamWriter Write method to write out part of the string to file. such as if the machine is shut down half way through? or does the file not actually exist until the...
5
by: matthew | last post by:
Hi all, I am now writing a aspx that get a session variable (string) and then write it out using Response.Write. The string length is: 494710. But Response.Write only write the string...
10
by: Tibby | last post by:
I need to read/write not only text files, but binary as well. It seems like on binary files, it doesn't right the last 10% of the file. -- Thanks --- Outgoing mail is certified Virus...
5
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
27
by: lovecreatesbea... | last post by:
This code snippet is an exercise on allocating two dimension array dynamically. Though this one is trivial, is it a correct one? Furthermore, when I tried to make these changes to the original...
9
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a .net application and am using the xml writer class to create an xml file that opens as an excel file. I am trying to write out the following but am having difficulty. <Row> <Cell...
0
by: kuguy | last post by:
Hi all, I'm new to the forums, so I hope this isn't in the wrong place... I have that "Software caused connection abort: socket write error" exception error that i've never meet before. ...
2
by: cmrhema | last post by:
Hi All , I have with me a server socket program, I am receiving all the clients, but what happens is i have to write it into a file. This consumes time. So we do not have a data loss, but as...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.