Solved

Remove the last zero character form a string

Posted on 2009-04-09
12
373 Views
Last Modified: 2012-05-06
Hi;
I have a string field full of data like this" 18 10 6 4 1 0"
I mean that is the last character always space then zero "0"
I need function  to remove this zero  at all
please
0
Comment
Question by:Mohammad Alsolaiman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 5

Assisted Solution

by:brandonvmoore
brandonvmoore earned 50 total points
ID: 24113557
Use the Left() and Len() functions:

select left(fieldname, len(fieldname) - 1)
or
select left(fieldname, len(fieldname) - 2)

Use "-1" if you want to leave the space on the end or "-2" if you want to get rid of the space and the 0.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24113567
what if you had something ending with 10, is that a possibility?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24113573
if always space then 0 then brandon's post will work for you. If not always space and 0 then try this

if last two chars is space and 0 then strip it off else leave as as

mystrippedfield: iif(right$(myfield,2) = " 0",left$(myfield,len(myfield)-2),myfield)

this can be put in your sql

0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 65

Expert Comment

by:rockiroads
ID: 24113575
is this stripping just for display purposes or do you want to update the data? what Ive posted is for select. If you want to update the data, it is like this

update mytable
set myfield = left$(myfield,len(myfield)-2)
where len(nz(myfield,""))>1 and right$(myfield,2) = " 0"

Need to actually take into account any fields that are null or have 1 char in them so added len(nz(myfield,""))>1
same would be needed in the select as well I guess


0
 

Author Comment

by:Mohammad Alsolaiman
ID: 24113600
no i want some thing fore fields i declare, but not in sql statement
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 450 total points
ID: 24113609
sorry? fields you declare. Do you want vba

dim mynewstring as string

mynewstring = iif(right$(myfield,2) = " 0",left$(myfield,len(myfield)-2),myfield)

Otherwise Im not sure what you mean
0
 

Author Comment

by:Mohammad Alsolaiman
ID: 24113636
yes u r wright,
but there some thing else
i think the zero is in the first character,  and not as i mention before .
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24113658
so it is zero and space
or space and zero

if zero and space

if len(myoldstring)>1 and left$(myoldstring,2) = "0 " then
    mynewstring = myoldstring
else
    mynewstring = myoldstring
end if

to replace myoldstring only

if len(myoldstring)>1 and left$(myoldstring,2) = "0 " then
    myoldstring = mid$(myoldstring,3)
end if


to replace space and zero, change "0 " to " 0"
0
 

Author Closing Comment

by:Mohammad Alsolaiman
ID: 31568826
wonderful
0
 

Author Comment

by:Mohammad Alsolaiman
ID: 24113667
thanks a lot rocki
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24113694
No probs
in case you got null strings, just add the check for the length
0
 

Author Comment

by:Mohammad Alsolaiman
ID: 24114277
clear
thanks again
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question