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

grabbing 6 characters from the middle of a variable length string

I need to grab the 6 numbers from the middle of a string like ABCDEF123456A and ABCDEFGH123456A. So I want 6 characters starting at the 7 last character in a string. I tried mid(TEXT, len(TEXT)-7,6) but I get a proceedural error.
mid(TEXT,7,6) has no issues but the starting point varies and the mid() does not seem to like the LEN(TEXT)-7 in the middle.
Is there a better way?
Mar 5 '14 #1

✓ answered by Rabbit

Please post the full error message.

I suspect you have a string less than 8 characters long and len - 7 is 0 or negative.

4 1702
NeoPa
32,556 Expert Mod 16PB
Timelord?

Try :
Expand|Select|Wrap|Line Numbers
  1. Mid(strData, Len(strData) - 6, 6)
Alternatively, the following will also work :
Expand|Select|Wrap|Line Numbers
  1. Left(Right(strData, 7), 6)
Mar 5 '14 #2
Rabbit
12,516 Expert Mod 8TB
Please post the full error message.

I suspect you have a string less than 8 characters long and len - 7 is 0 or negative.
Mar 5 '14 #3
Thanks Rabbit, you are right. There are shorter strings. Focussed on the problem at hand and not the whole picture. :-)
Thanks NeoPa. I will try your suggestion.
It looks like I will need to set up some kind of conditional test to deal with different strings as some look like AB123456 and some like ABCDE123456A.
Mar 6 '14 #4
NeoPa
32,556 Expert Mod 16PB
The point (one of them at least) I was trying to get across is that you don't want Len() - 7 at all in the scenario you described, but Len() - 6.

If you use either of the code snippets I suggested and the data is formatted as you described it in your first post then it will work perfectly for you.
Mar 6 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: srinivas reddy | last post by:
Hi, I have following questions. 1. Does va_arg allow one to read user defined types. My compiler allows but I am wondering whether it is true for all. 2. I wrote the following code. Pardon my...
1
by: arvee | last post by:
Hi - I'm updating an Oracle table with an empty string and getting the error: An unhandled exception of type 'System.Exception' occurred in system.data.dll Additional information: Parameter...
5
by: MLH | last post by:
I'm working with lots of long strings now, it seems. I have to import them & parse them constantly. The A97 memo field type supports only 32768 chars. What happens when this is processed... Dim...
17
by: Olivier Bellemare | last post by:
I've tried to make a function that returns the middle of a string. For example: strmid("this is a text",6,4); would return "is a". Here is my code: char *strmid(char *texte, int depart,...
7
by: tano | last post by:
Hello, I have to insert a char in the middle of a string, I have written two functions but I don't know what is the better? The problem is: if I use malloc() I copy all the string with the new...
14
by: Luiz Antonio Gomes Pican?o | last post by:
How i can store a variable length data in file ? I want to do it using pure C, without existing databases. I'm thinking to use pages to store data. Anyone has idea for the file format ? I...
1
by: Anandan | last post by:
Hi, This is regarding Dataset Filter: WILDCARD CHARACTERS Both the * and % can be used interchangeably for wildcards in a LIKE comparison. If the string in a LIKE clause contains a * or %,...
10
by: uche | last post by:
Hello all! I have thought about this question for a long time and I would like to know your opinion about it: In C, a variable-length string can be carried in RAM as a sequence of ASCII characters...
13
by: lak | last post by:
I want to know what is the variable length in c. I K&R they stated that atleast 31 character. But I give 1 lakhs length to a variable, but my compiler doesn't say any error. It accepts it.Then...
27
by: aravind | last post by:
Hi, I need to develop a menu system for a project of mine. The menu will be displayed on a character LCD display driven by ARM7 Microcontroller. For this purpose i wish to construct a structure in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.