Trim last two characters of a String
Hi,
I have a task to trim the last two characters of a string in a column and get the rest as output for comparison purpose.
the length of column value is not fixed.
For example
I/p O/p
India_1 India
America_2 America
I achieved the result using the below query:
SELECT SUBSTR (TRIM ('India_1'), 1, LENGTH (TRIM ('India_1')) - 2) FROM DUAL;
I have used the trim function to remove the leading and trailing spaces in the column value.
Could somebody please let me know if there is a better way to get the result .. like in one shot query.
Thanks,
Pratik
I have a task to trim the last two characters of a string in a column
SQL> with t as (
select 'India_1' str from dual union all
select 'America_2' from dual
select regexp_replace(str, '..$') str1 from t
STR1
India
America
2 rows selected.
Similar Messages
-
Need to check whether first two characters of a string is Alphabets or not
Hi,
Need to check whether first two characters of a string is alphabet or not.
Lets say for Ex,
String as 'DE123456' i need to check whether first character is non-numeric and then second character as non numeric.
kindly help me on this.
IF length(trim(p_parserec(31))) = 22 AND p_parserec(31) LIKE 'DE%' THEN
AUFTRAGGEBERKONTONR := trim(p_parserec(31)) ;
ELSIF (length(trim(p_parserec(31))) > 22 AND length(trim(p_parserec(31))) < 35) AND p_parserec(31) NOT LIKE 'DE%' THEN
AUFTRAGGEBERKONTONR := lpad(trim(p_parserec(31)), 34, 0) ;
ELSIF length(trim(p_parserec(31))) > 10 AND ascii(substr(p_parserec(31), 1, 2)) between 48 and 57 THEN
AUFTRAGGEBERKONTONR := lpad(trim(p_parserec(31)), 10, 0) ;
ELSE
p_errorcd := sqlcode ;
p_errordata := sqlerrm ;
END IF ;
Note : In the third else if condition the character should be greater than 10 and first 2 characters should not be alphabets.Siva.V wrote:
Need to check whether first two characters of a string is alphabet or not.
To this requirement only regexp_like will work too! No need of some other string function!
Like:-
-- in regexp_like last parameter shows to ignore case (optional).
SQL> with t as
2 (select 'AB123456' as key from dual union all
3 select 'CD234567' from dual union all
4 select 'A1234567' from dual union all
5 select 'A52H4341' from dual union all
6 select 'Dk274341' from dual union all
7 select 'DE234556' from dual)
8 select key
9 from t
10 where regexp_like(key,'^[A-Z]{2}','i') -- even '^[[:alpha:]]{2}' or '^\D{2}' pattern can be replaced for same result..
11 /
KEY
AB123456
CD234567
Dk274341
DE234556
Thanks! -
Last two characters are cut out when entering data in a text form
Whenever I try leaving a comment on a page, it always cuts out the last two characters, and replaces them with "Pr". This happens across multiple browsers, (Chrome, FF, and Camino), but not Safari.
In addition, if a '<' character was put in, it'll cut out the last two characters in its code, and replace them with Pr again, leaving %Pr.
This happens on a mac (I'm posting for my friend who I talk to all the time).We did end up checking keyboard related settings in her Mac Preferences, but there wasn't anything related. I will end up trying Apple's forums if no one here can help. Anyways the "Pr" I believe might've come from the source code, as there is "editProfile" in the page. I don't really do web development, so I'd have no idea here. This is the page's source from around that area btw (I had to convert them to all HTML character codes because it kept parsing it):
<div class="clFloat"></div></div></div><div class="horizLine"><hr/></div><div 
class="dataSection"><a class="rt" id="addcmtlnk" 
href="javascript:void(0);">Add Comment</a><label>Comments</label><div id="postcmt" 
class="dataFrameHLFB hidden"><div class="userEntry"><div 
class="editProfile"><form ajaxify="1" action="http://www.onverse.com/profile/ajax/comments/add.php" 
method="POST"><input name="toid" type="hidden" 
value="70981" /><table class="frame" 
cellspacing="0"><tr><td class="imageCell"><div class="smallImgFrame"><a 
href="http://www.onverse.com/profile/profile.php?id=5414"><img src="http://photos.onverse.com/photo.php?size=2&amp;profile=5414" alt="Pluto 
is a Planet" 
title="Pluto is a 
Planet" /></a></div></td><td class="commentCell"><p><a 
class="user" href="http://www.onverse.com/profile/profile.php?id=5414">Pluto is 
a Planet</a></p><div class="editFrame"><textarea 
name="text"></textarea></div><div class="submit"><INPUT type="submit" 
value="Post Comment" /></div></td></tr></table></form></div></div></div><div 
id="moreDropGroup_ldt" class="hidden"><img src="http://staticdata.ovstatic.com/img/bar_loading.gif" 
alt=""/></div><div id="moreDropGroup"><script type="text/javascript">
And this is what it looked like to me: http://img442.imageshack.us/img442/5656/97668645.png
Thanks for your reply, I appreciate it! -
How can I do field validation on the last two characters of a text field?
I have a text field. The user is required to enter the last two characters as numbers. I want to apply validation on this field. How can i achieve the same?
EX: If the user enter ABCDE, an error messgae stating the last two digit should be numeric.
I tried using the below in the field validation which did not work.
(0+Right([<ExternalSystemId>],2)) > 0 AND (0+Right([<ExternalSystemId>],2)) < 99.
Any ideas would help?Try this-
FindOneOf(Right([<Field1>],"2"),"abcdefghijklmnopqrstuvwxyz")=0
rgds,
Amit -
How do I drop the last 3 characters in a string?
Hello. I'm trying to find a way to drop the last 3 characters in a string. The length varies because it is a last name field. The problem is that when a customer has a suffix on their name, III for example, it is appended to the last name all in the last name field. If I use the ProperCase function, I end up with "Smith Iii". How can I tell it to drop the last 3 characters? I'll then append an UpperCase edition of the last 3 characters to that. Thank you!
Use the instring and right string functions then UpperCase
-
How to get the last 3 characters of a string occuring after a character / alphabet without using REGEXP_SUBSTR ?
Ex: 10000A001 is the string.
Note: - I want to use it in Oracle reports 6i, therefore i cannot use the statement REGEXP_SUBSTR
SanjaySELECT '1000'|| INITCAP ('a') || '001'
FROM DUALregards,
friend -
Hi Gurus,
I have a requirement to show only those values of an infoobject where,
First 2 characters are AB.I have written code for this and is working.
Additionally I need to show the values where the last 2 characters are PR.
How to write code for this part.
Please help.
Regards,
SunitaHi,
Write a simple code.
Suppose value is "ABCDPR".
DATA :V_CHAR type any,
v_char1 type c,
V_LENGTH type n.
v_lenght = strlen(v_char).
v_length = v_length - 2.
v_char1 = v_char+v_length(2).
This will give you the last two characters of the string.
- Jaimin -
how can i change the last 4 characters of a string to .txt?
Come, come. Have you not even bothered to look at the String api??????????????????
String s = "changeme";
s = s.substring(0, s.length()-4) + ".txt";Ta da....
Rob. -
Removing last 2 characters from string field
I am trying to remove the last 2 characters of a string field.
there is no consistant length in the field
316R1
12364R1
i want to remove everything after R
i tried instrrev but i that didnt do it.
is there a way to say
start position1 and go the R
thanksformula,
left (field, length_formula) is the solution
the length_formula is the number of chars form left
f.i
left(field, length (field)-2)
left (field, InstrRev, field,"R")
of course a combination with Right is also possible -
How can I select the last 2 chars of a string
Hello all,
I am trying to select the last 2 characters of a string to match them to another string. This is for a Poem generator that contains 20 or so words and I have to pick 2 words at random, them look at the last 2 characters to see if they match in each string. Say "Plain" and "Rain" would match because they both have "in" at the end. The length of each word could vary. I don't want this doing for me just what Method should I be looking at.
Thanks.hi,
try this:
public class StringTest {
public static void main(String args[]) {
StringTest obj = new StringTest();
obj.same();
void same() {
String rain = new String("Rain");
String plain = new String("Plain");
int rainLength = rain.length();
int plainLength = plain.length();
if(rain.substring(rainLength-2).equals(plain.substring(plainLength-2))) {
System.out.println("same");
else {
System.out.println("different");
}you can use the length method to get the length of a string and then use the substring method, passing it length-2, so get the last 2 chars. -
Validating Characters in a String
Hey everyone first post here, I have a question about validating characters in a string. I have a program where u need to enter an item code and it must have 2 letters in the begining and 3 numbers at the end, all one word.
Now I already have an error test to see whether or not the string is 5 characters and all that but i have no idea where to start on checking whether or not each character meets the criteria, i've thought of checking each character individually but I thought there had to be an easier way.yea right now i'm completley lost, i kind of
understand regex but i just have no idea how i would
type it out, Go step by step. You want a string that has five characters. The first
test could be this (let's call that string 'string' by lack of creativity):if (string == null || string.length() != 5) return false;This is the first test: if there is no string or if it doesn't contain five
characters, all bets are off. Here's the second test:for (int i= 0; i < 2; i++)
if (!Character.isLetter(string.charAt(i)))
return false;If the first two characters aren't letters the string is incorrect (according
to your specifications). Here's the last test:for (int i= 2; i < 5; i++)
if (!Character.isDigit(string.charAt(i)))
return false;If all those tests succeed, you simply do this:return true;All you have to do now is join these code fragments in a simple method
and you're in business. Comprendo, partner?
kind regards,
Jos -
wondering.. anyone knows how to remove characters in a string
e.g.
string: applepie
after removing last 3 chars become "apple"
thanks...That of course will only work for this example. Better solution is to use indexOf() to locate the position of the string you wish to remove. If the string you wish to remove is in the middle, then you will have to do a bit of extra work and concat two substrings.
-
Removing non english characters from my string input source
Guys,
I have problem where I need to remove all non english (Latin) characters from a string, what should be the right API to do this?
One I'm using right now is:
s.replaceAll("[^\\x00-\\x7F]", "");//s is a string having chinese characters.
I'm looking for a standard Solution for such problems, where we deal with multiple lingual characters.
TIA
NitinNitin_tiwari wrote:
I have a string which has Chinese as well as Japanese characters, and I only want to remove only Chinese characters.
What's the best way to go about it?Oh, I see!
Well, the problem here is that Strings don't have any information on the language. What you can get out of a String (provided you have the necessary data from the Unicode standard) is the script that is used.
A script can be used for multiple languages (for example English and German use mostly the same script, even if there are a few characters that are only used in German).
A language can use multiple scripts (for example Japanese uses Kanji, Hiragana and Katakana).
And if I remember correctly, then Japanese and Chinese texts share some characters on the Unicode plane (I might be wrong, 'though, since I speak/write neither of those languages).
These two facts make these kinds of detections hard to do. In some cases they are easy (separating latin-script texts from anything else) in others it may be much tougher or even impossible (Chinese/Japanese). -
I have a formula column cf_1 in my report 'purchase order'which actually converts the numeric value of a summary column 'AMOUNT' to the character form.This is to show the amount both in words&numerical figures.Next to cf_1 I have attached a text string 'only' and the same has been anchored to cf_1.The horizontal elasticity property of cf_1 is set to 'variable'.Ideally at run time, the formula coulmn with the text string,for example, should read 'ONE HUNDERD ONLY'.But it always omits the last two letters of cf_1 and instead gives the output like this-'ONE HUNDR ONLY'.Can anybody tell me as to how this problem can be fixed?
My Oracle version 8i& Reports 6i
Thank you in advance
JayThis is possibly to do with the "width" of the formula column - it's probably set to "10" and is therefore truncated at this point.
Another way of creating your output, rather than having variable sized fields and anchors, is to just have a single boilerplate object. You can reference the formula column directly in the boilerplate object and insert any surrounding text: eg: "&<cf_1> only". This will give you the output you want without requiring the field and is simpler to debug and manage. -
My backspace key delete two characters in Firefox.
My backspace key delete two characters in Firefox. How may I solve this problem?
It works in other programs such as Office well. My OS is WIN7.
Please help me.Application Basics
Name: Firefox
Version: 29.0
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
Crash Reports for the Last 3 Days
All Crash Reports (including 1 pending crash in the given time range)
Extensions
Name: Adblock Plus
Version: 2.6
Enabled: true
ID: {d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}
Name: IDM CC
Version: 7.3.73
Enabled: true
ID: [email protected]
Name: Right Inbox
Version: 1.0
Enabled: true
ID: {eb692b9a-0dce-45fa-b0e6-765d83e386bd}
Name: Adobe Acrobat - Create PDF
Version: 1.0
Enabled: false
ID: [email protected]
Name: PDF Architect Converter For Firefox
Version: 1.0
Enabled: false
ID: [email protected]
Important Modified Preferences
browser.cache.disk.capacity: 358400
browser.cache.disk.smart_size_cached_value: 358400
browser.cache.disk.smart_size.first_run: false
browser.cache.disk.smart_size.use_old_max: false
browser.places.smartBookmarksVersion: 6
browser.sessionstore.upgradeBackup.latestBuildID: 20140421221237
browser.startup.homepage: www.google.com
browser.startup.homepage_override.buildID: 20140421221237
browser.startup.homepage_override.mstone: 29.0
dom.mozApps.used: true
extensions.lastAppVersion: 29.0
network.cookie.prefsMigrated: true
places.database.lastMaintenance: 1399615634
places.history.expiration.transient_current_max_pages: 104858
plugin.disable_full_page_plugin_for_types: application/pdf
plugin.importedState: true
privacy.sanitize.migrateFx3Prefs: true
storage.vacuum.last.index: 0
storage.vacuum.last.places.sqlite: 1399534769
Graphics
Adapter Description: ATI Mobility Radeon HD 5470
Adapter Drivers: atiu9p64 aticfx64 aticfx64 atiu9pag aticfx32 aticfx32 atiumd64 atidxx64 atidxx64 atiumdag atidxx32 atidxx32 atiumdva atiumd6a atitmm64
Adapter RAM: 1024
ClearType Parameters: Gamma: 2200 Pixel Structure: R ClearType Level: 100 Enhanced Contrast: 300
Device ID: 0x68e0
Direct2D Enabled: Blocked for your graphics driver version. Try updating your graphics driver to version 10.6 or newer.
DirectWrite Enabled: false (6.1.7600.16385)
Driver Date: 1-22-2010
Driver Version: 8.692.1.0
GPU #2 Active: false
GPU Accelerated Windows: 1/1 Direct3D 9
Vendor ID: 0x1002
WebGL Renderer: Google Inc. -- ANGLE (ATI Mobility Radeon HD 5470 Direct3D9Ex vs_3_0 ps_3_0)
windowLayerManagerRemote: false
AzureCanvasBackend: skia
AzureContentBackend: cairo
AzureFallbackCanvasBackend: cairo
AzureSkiaAccelerated: 0
JavaScript
Incremental GC: true
Accessibility
Activated: false
Prevent Accessibility: 0
Library Versions
NSPR
Expected minimum version: 4.10.3
Version in use: 4.10.3
NSS
Expected minimum version: 3.16 Basic ECC
Version in use: 3.16 Basic ECC
NSSSMIME
Expected minimum version: 3.16 Basic ECC
Version in use: 3.16 Basic ECC
NSSSSL
Expected minimum version: 3.16 Basic ECC
Version in use: 3.16 Basic ECC
NSSUTIL
Expected minimum version: 3.16
Version in use: 3.16
Maybe you are looking for
-
Had nothing but praise for my X3-02 for the 3 months ive had it.... Until today. having lunch i turned my phone off as i always do, turned it back on after lunch to find it wasnt accessing the phone memory and therefore the favourites bar, contacts,
-
hi all, i want to get the BOM RAW material cost for FG, like cost showing in ck13n t-code, pls note me the table or FM to get this, Thanks & Regards Usman
-
Hello Gents, Anybody knows why I can't access to VI (*.exe) on remote PC. On remote PC has been installed only standard 8.6 Run Time Engine. Do I need to install additional parts like NI LabVIEW Run-Time Engine Web Server or/and LV Web Server? And is
-
ITS Mobile Date Field Problemn
In ITS Mobile I developed a screen which contains a date field. I click question button to select a date, it opens a new screen which includes a calendar. But I can not select a date because no clickable days in new date selection screen. What can i
-
Configuring SP13 to use dynamic memory
I am aware that SharePoint 2013 does not support the use of dynamic memory due to "certain applications" that need fixed memory allocation. The only example that is ever offered of one of "these applications" is the Distributed Cache. All well and go