473,667 Members | 2,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.valu e =
TheString.subst ring([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 1374
On 1 Sep 2004 08:49:48 -0700, Abby Lee <ab*******@hotm ail.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.valu e =
TheString.subst ring([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.valu e =
TheString.subst ring([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="1234 56789A"
alert(theString .substring(0,6) +theString.subs tring(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*******@hotm ail.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.valu e =
TheString.subs tring([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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
1494
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 particular graphic file. Each field is unique and there are approximately 4000 records.A typical string I wsh to edit is as follows D:\diagrams\abc_123.tiff . (one of 4000) D:\diagrams\abc_1234.tiff etc to
13
15972
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 reason I ask is that I am programming on a RISC system where division is quite expensive, and I want to be able to extract the digits from an integer (the integer will be from 1 to 6 digits long, and I know how many digits are in the number).
2
2813
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 C#. The only significant problem that I have encountered in the conversion is this one - extracting an icon from the 'KTEntryPoint' program into the software suite and placing that icon on the PC Desktop.
3
3337
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 when I click on view_source. The source I need is contained inside IFRAME tags (which contain references to jsp pages)... The html content isn't available when I look at the innerHTML of the document returned in the DocumentComplete event of the...
4
2561
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
1937
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 below is working to a degree in IE7. As I have not yet parsed http.responseText, I am getting all the code in parts.php in the alert. My php script query creates two php arrays, one a single array and a two-dimensional array such as array. My...
4
2319
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: TECH_ACT=2HL91002:TGT_START=12-NOV-07:CAM_CODE=AKJBA:DA=HL:WBS=DES071702: I'd like to extract the element CAM_CODE=AKJBA but the string after the "=" sign can vary in length between rows. Does anyone have a code snippet in their library that might do this ... or is there a built-in function that I...
10
4068
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 Minutes.
2
1576
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 & _ "==============================" & vbCrLf & _ "2nd garbage blah, blah.. " & vbCrLf & _ "==============================" & vbCrLf & _ "3rd garbage blah, blah.. " & vbCrLf & _
0
8458
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8366
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8650
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7391
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2779
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.