473,324 Members | 2,501 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,324 software developers and data experts.

extracting parts of a string

I have a string with 10 charaters 123456789A.
I only want the first 6 charaters followed by the last two...getting
rid of the 7th and 8th charaters.

If I use document.forms[0].MyTextBox.value =
TheString.substring([0-5])...I get the first 6 charaters.
([0-5],8,9) does not work nor does ([0-5],[8-9]) and I get just as bad
results with (0,1,2,3,4,5,8,9)

how do I get a string with the 7th and 8th charaters missing?
Jul 23 '05 #1
3 1359
On 1 Sep 2004 08:49:48 -0700, Abby Lee <ab*******@hotmail.com> wrote:
I have a string with 10 charaters 123456789A.
I only want the first 6 charaters followed by the last two... getting
rid of the 7th and 8th charaters.

If I use document.forms[0].MyTextBox.value =
TheString.substring([0-5])...I get the first 6 charaters.
([0-5],8,9) does not work nor does ([0-5],[8-9]) and I get just as bad
results with (0,1,2,3,4,5,8,9)
I'm not quite sure what your expectations are, but the substring method
only takes two arguments: the zero-based index of the starting character,
and the index of a second character. The returned string doesn't include
the character specified by the second index.
how do I get a string with the 7th and 8th charaters missing?


To do what you want, you'll need to call the method twice:

str.substring(0, 6) + str.substring(8)

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Abby Lee wrote:
I have a string with 10 charaters 123456789A.
I only want the first 6 charaters followed by the last two...getting
rid of the 7th and 8th charaters.

If I use document.forms[0].MyTextBox.value =
TheString.substring([0-5])...I get the first 6 charaters.
([0-5],8,9) does not work nor does ([0-5],[8-9]) and I get just as bad
results with (0,1,2,3,4,5,8,9)

how do I get a string with the 7th and 8th charaters missing?


theString="123456789A"
alert(theString.substring(0,6)+theString.substring (8))

Mick
Jul 23 '05 #3
JRS: In article <80**************************@posting.google.com >,
dated Wed, 1 Sep 2004 08:49:48, seen in news:comp.lang.javascript, Abby
Lee <ab*******@hotmail.com> posted :
I have a string with 10 charaters 123456789A.
I only want the first 6 charaters followed by the last two...getting
rid of the 7th and 8th charaters.

If I use document.forms[0].MyTextBox.value =
TheString.substring([0-5])...I get the first 6 charaters.
([0-5],8,9) does not work nor does ([0-5],[8-9]) and I get just as bad
results with (0,1,2,3,4,5,8,9)

how do I get a string with the 7th and 8th charaters missing?


Str1 = "123456789A"
Str2 = Str1.replace(/^(......)../, "$1") // 1234569A
or Str2 = Str1.replace(/^(.{6}).{2}/, "$1") // 1234569A

Method is best suited to fixed patterns, but can be adapted for variable
numbers.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

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

Similar topics

2
by: bozdog | last post by:
I have recently imported several fields from a spreadsheet(excel) and wish to update a field using an update query. The particular field is imported as a text string and defines a path for a...
13
by: Kosio | last post by:
Hello, I know of a way to extract digits from a number using the %10 and divide by 10. But I am wondering if there is an algorithm out there that does not use a divide by 10 feature. The...
2
by: Dickyb | last post by:
Extracting an Icon and Placing It On The Desktop (C# Language) I constructed a suite of programs in C++ several years ago that handle my financial portfolio, and now I have converted them to...
3
by: news | last post by:
I am trying to get at the source of a web page. Looking at the innerHTML element is only part of the story. In IE, right-clicking on various different parts of the page gives me different results...
4
by: dor | last post by:
i have an input file named input.txt where all the data looks like this: (4,10) 20 (5,3) 13 (7,19) 6 .. .. .. the numbers are random. i need to use every number in each line
1
by: rpjd | last post by:
I am completely new to this so please bear with me here. My project involves a webpage executing php scripts via an xmlhttprequest which queries a database and returns data to the webpage. This code...
4
by: Keith Wilby | last post by:
On a bit of a no-brainer with this. I have a field containing composite data which is imported from another system. Here's a sample: ...
10
by: Dan | last post by:
I have a number of strings that represents time. 1w 2d 3h 15m 2d 3h 15m 4h 30m 45m I want to extract the number parts of my strings into separate variables for Weeks, Days, Hours and...
2
by: thomasc | last post by:
Hello, I have a question about manipulating string in VB.NET2003. I have a string that looks as follows: MyString = "1st garbage blah, blah.. " & vbCrLf & _ "=============================="...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: 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

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.