PMString::substring
Hello people.
This is a general question about how best to write some code.
In my many projects I have lots of examples of this kind of code:
PMString *d, Data("SomeString of decent length");
d = Data.Substring(0, 12);
PMString newString = *d;
delete d;
This code could be simplified to something like this:
PMString newString, Data("SomeString of decent length");
newString = *Data.Substring(0, 12);
but writing it this way leads to memory leaks (usually a good many of them).
Of course, one could simply use d as a pointer in the code, but one still needs to remember to delete the data after the program is finished with it.
Is there a more elegant way to deal with the return value of PMString::Substring in the InDesign SDK?
TIA!
John
You way should work, although your define wasn't quite complete.
Just as a matter of style I think I would prefer not to hide your intentions too much with PMSPtr.
Gone are the days of compilers which only cope with 8 character variable and type names!
Additionally, I would prefer typedef over define.
typedef K2::scoped_ptr<PMString> PMStringPtr;
Then your constructor would work in the same way.
PMStringPtr theDay( inDate.Substring ( 0, 2 ) );
Simple, and it makes the code tidy and self-explanatory. What more could you want? :-)
Regards
Caerwyn
Similar Messages
-
Getfilename into a PMString without file's extension
Hi guys,
I am wondering whether it is possible to get the filename of a file without its extension.
For example when i call the following code on the files "test.indd", the whole filename, with extension .indd is returned.
PMString truncP = idFile.GetFileName();
I want to get only the word "test".
Failing such a possibility, is some sort of PMString manipulation possible to extract only the substring from character 0 to position of character "."
I cant do that in SDK while this is fair simple in C++. Been looking in the sdk doc for the PMString members and I keep trying things but they dont work out. But am sure its fairly simple to achieve.
Thanks
AliciaHello Alicia and Nadia:
In the file SnpManipulateAssignment.cpp (comes with the CS3 SDK--don't know about earlier versions) you can find the following bit of code:
IDFile sysFile = fileChooser.GetIDFile();
/* irrelevant code deleted */
PMString baseFileName;
FileUtils::GetBaseFileName(sysFile, baseFileName);
HTH!
John -
IF and SUBSTR in XML Publisher
Hi
I am developing a XML RTF template for a report.
All I am trying to do is, if first 4 letters of the data of xml tag ITEM = 'Summ'
then print a constant word 'Notes'
<?if: xdofx:substr(ITEM,1,4)=’Summ’?> Notes<?end if?>
I have been trying hard. IF and SUBSTR is not at all going along. Always throwing some error. Can some one please help me to resolve this issue
ThanksHi,
I have a similar requirement, however instead of static text in the example i.e ITEM I am trying to get a substring from a tag value directly. Ex - Tag Value <eod>23-10-2009<eod>. I am trying to pick up the value 10 in the particular example and trying to compare with 1, which would be false and hence I need to print as false. I cannot use a hardcoded value since the value between the tags <eod> is dynamic and I need to use that itself.
Can you please provide me with the sytax which can achieve this?
Regards,
Praseed -
Can we use Trunc,Substr in Excel templates
Hi All,
I have a date xml tag with value like "2012/04/01 00:00:00" i need to show this in excel output as "01-APR-2012".
I am using Excel template, need your help to achieve the same.
I tired to use Trunc,Substr,Format date but nothing is working.
Please give me your valuable inputs to solve this issue.
Thanks
RajehsVarma,
Thanks for the reply, i have already checked the link but it doesn't have syntax to use Trunc,substr etc. functions.
Also date in example is - "1996-02-03T00:00:00.000-07:00" , but in my case date format is different "2012/01/01 00:00:00".
Thanks
Rajesh -
How to find a substring in XML-lookslike string?
Hi,
I have a question and wondering if anyone can help me with it.
We have Java tool that does a string replacement inside another string (that is actually an XML request). It works fine when searching for a simple substring (that exists within 1 line of the XML string).
But when I'm trying to find and replace a substring that covers more then 1 line of XML request - it does not work. And I'm not sure what is wrong or (more importantly) how to make it work.
There is no return or new-line chars seen in the XML request.
To make it more clear - here is what I have and trying to do:
<a>
<a>
<b>
<c>
<d> </d>
<c>
<c>
</c>
</c>
</c>
</b>
</a>
</a>
If I'll seach for either <c> OR </c> OR <d> </d> it all works fine ... BUT if Itry to find
</c>
</b>
which will be copied directly from the XML request and past into field - thus it will look like this (horisontal line instead of vertical) </c> </b> - it does not workqavlad wrote:
But when I'm trying to find and replace a substring that covers more then 1 line of XML request - it does not work. First statement - "more than 1 line"
There is no return or new-line chars seen in the XML request.Second statement.
There is no way that I can understand what you meant in your first statement in terms of your second.
If there are no end of line characters at all then there is only one line. Period.
If there are end of line characters, of any kind, then that would really suggest the source of the problem. -
Hi All,
i am a comma seperated values into a variable. below are the values.
"1234567,3,124567,3,14"
the length of the values can vary. eg the output can also be
"123,3,124567,443,1224"
I need to get each value and store it a separate variable. is it possible using substr..?
Please help me out...Hi,
Here's how you can split a delimited list into parts in Oracle 9:
WITH got_part_cnt AS
SELECT pk
, csv
, 1 + LENGTH (csv)
- LENGTH (REPLACE (csv, ',')) AS part_cnt
FROM table_x
, cntr AS
SELECT LEVEL AS n
FROM ( SELECT MAX (part_cnt) AS max_part_cnt
FROM got_part_cnt
CONNECT BY LEVEL <= max_part_cnt
, got_pos AS
SELECT p.pk
, p.csv
, c.n
, INSTR ( ',' || p.csv
, 1
, c.n
) AS start_pos
, INSTR ( p.csv || ','
, 1
, c.n
) AS end_pos
FROM got_part_cnt p
JOIN cntr c ON c.n <= p.part_cnt
SELECT pk
, csv
, n
, SUBSTR ( csv
, start_pos
, end_pos - start_pos
) AS item
FROM got_pos
ORDER BY pk
, n
;Pk is the primary key of table_x. If you don't need it, you can omit it.
Of course, this will work in versions later than 9, but you wouldn't want to if you could use REGEXP_SUBSTR. -
How we get all string from substring,.,.
Hi,
I am doing one application . In that i have to enter substrubg in search user inputfield and then i click on search . Not i want to show all user which contain that substring . So please guide in that.
Example...
Like i am writing "ab*" then all users comes which contain ab substring.
Regards,
Gurprit BhatiaHi,
Try this logic.
String searchString="ab*";
searchString=searchString.subString(0,searchString.length-2);
String[] matchedArray=new matchedArray(100);
int j=0;
//Let your compare strings be in an array strArray
for(int i=0;i<strArray.length;i++){
String temp=strArray<i>.subString(0,searchString.length-2);
if(temp.equals(searchString)){
matchedArray[j]=strArray<i>;
j++;
Then display the matched String array.
Hope it helps.
Regards,
Srinivasan Subbiah -
Hi,
I have a table tablea where a column stores values like ABC LTD,BCD LTD,CEF LTD,DEFEF LTD.
I want the output as
ABC,BCD,CEF,DEF
i have used substr but could not frame the result as the last value stores DEFEF so culd not do substr(1,3) from the table
Any help will be needful for me
Edited by: user13443042 on Jan 26, 2011 2:31 AMYou mean like this?
SQL> ed
Wrote file afiedt.buf
1 select trim('.' from replace('ABC LTD,BCD LTD,CEF LTD,DEF LTD.',' LTD'))
2* from dual
SQL> /
TRIM('.'FROMREP
ABC,BCD,CEF,DEF
SQL>However, it looks like your data structure is wrong. You shouldn't store multiple values in a single string in a colulmn. These should be multiple records or multiple columns as appropriate. -
How to use substr in external table defnition.
Hi All,
Im using oracle 11g. I have an external table which is reading data from a file. For one of the column, i need to get only the first 250 characters. My external table defnition looks like this
create table tbl_substr
( col1 varchar2(20),
col2 varchar2(250)
organization external
( type oracle_loader
default directory XXXX
access parameters (
records delimited by newline
FIELDS TERMINATED BY '|'
missing field values are null
( col1 ,
col2 "substr(:col2,1,250)"
) ) location ('file.txt') )
reject limit unlimited
But this defnition gives an error when i do select * from tbl_substr
I want to use substr in external table defnition its self and not in SELECT. Also i dont want to crete a view to solve this. If anyone has done this please help.You need to play with COLUMN_TRANSFORMS
http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/et_params.htm#sthref1792
BTW, i too got it from Google. I was not aware about this :)
Amardeep Sidhu -
How to select a substring in oracle up to a more than one specific character
How to select a substring in oracle up to a more than one specific character
for ex : 121.051^NP: FAMILY PRACTICE ( trim the values before ^ )
121.051^*NP: FAMILY PRACTICE (trim the value before *).
with below function I can only get rid of ^ , I want both the specific characters ^ and ^* to be removed at the same time.
SUBSTR(p.phys_sub_grp_2_desc,INSTR(p.phys_sub_grp_2_desc, '^') +1)Another option is to boldly replace 'em:
SQL> with t as (
2 select '121.051^NP: FAMILY PRACTICE' str from dual union
3 select '121.051^*NP: FAMILY PRACTICE' from dual
4 )
5 --
6 -- actuel query:
7 --
8 select substr( replace(str, '*')
9 , instr(replace(str, '*'), '^')+1
10 ) str
11 from t;
STR
NP: FAMILY PRACTICE
NP: FAMILY PRACTICE
2 rows selected. -
How to use a parameter field value as a substring in a "like" statement?
Hi all,
I'm trying to use a parameter field in a Record selection formula where the parameter field value would be a substring of the data stored in the field.
My parameter field (SlctResearcher) is constructed as follows:
Type: string
List of Values: static
Value Field: (Reports) RptAuthors
(in Value Options) Allow custom values?: True
{Reports.PubDate} in DateTime (2009, 04, 01, 00, 00, 00) to DateTime (2010, 03, 31, 23, 59, 59) and
{Reports.RptAuthors} like "*{?SlctResearcher}*"
When I hit F5 to generate the data, I get no results (and the parameter prompt field does not even come up...)
If I modify the formula to put a hard-coded string, like
"*Jones*"
after the 'like', I get results (all the reports where "Jones" is a substring in the RptAuthors string.) If I modify the formula to just use the parameter field without the quotes/stars like:
{Reports.PubDate} in DateTime (2009, 04, 01, 00, 00, 00) to DateTime (2010, 03, 31, 23, 59, 59) and
{Reports.RptAuthors} like {?SlctResearcher}
I do get the parameter prompt field, but still no results even if I put in a valid substring value (since it is not searching for a substring anymore...)
How can I do this?
Thanks,
Will1st thing... Make a copy of your report before doing anything!!!
To use a SQL Command, you'll want to open the Database Expert and look at the Current Connections. Expand the data source and the 1st option you see is the Add Command option.
To find the SQL That CR is currently using, choose Database from the menu bar and select Show SQL Query...
You can copy this and paste it directly into the command window. (If you you can write your own SQL you don't need copy CR's, it's just an option.)
You'll also want to take not of any parameters that you have, you'll need to add them the the Parameter List of the command as well... be sure to spell them EXACTLY as they are in the design pane.
Anyway, once the SQL statement is in the Command window you'll be able to alter the WHERE clause to use the wild cards.
For future reference... What type of database are you reporting against???
Jason -
How do I update the substring of a string value?
UPDATE table1
SET SUBSTR (TO_CHAR(field_value),3,2) = ' 50' and SUBSTR (TO_CHAR(field_value),5,2) = '50'
where ( SUBSTR(TO_CHAR(field_value), 3, 2) = '100' ) or ( SUBSTR(TO_CHAR(field_value), 5, 2) = '100' )tried the above in TOAD and I got "ORA-00927: missing equal sign." Please help!
data type for field_value is number. oracle version is 10g
thank youHere's an example of how you can do it:
SQL> CREATE TABLE x
2 AS
3 SELECT 'SOME50HERE' AS field_x
4 FROM dual;
Table created.
SQL> SELECT * FROM x;
FIELD_X
SOME50HERE
1 row selected.
SQL> UPDATE x
2 SET field_x = SUBSTR(field_x,1,4)
3 || '75'
4 || SUBSTR(field_x,7)
5 ;
1 row updated.
SQL> SELECT * FROM x;
FIELD_X
SOME75HEREBasically you need to break your string into three parts:
1. The part before the text you want to change.
2. The text you want to change.
3. The part after the text you want to change.
Then you concatenate them all together.
If #1 is not a known fixed number of characters, you can still use SUBSTR, by looking for the string you want to change like the following:
UPDATE x
SET field_x = SUBSTR(field_x,1,INSTR(field_x,'50') - 1)
|| '75'
|| SUBSTR(field_x,7)
; -
Error while converting CLOB to varchar using DBMS_LOB.SUBSTR() in Oracle11g
Hi
Whenever I am using DBMS_LOB.SUBSTR(columnname,4000,1) package for a clob column in a simple Select Query, the following error is thrown for Oracle 11g version.
ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 1.
Please find the installation details of the database and the character set
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
PARAMETER VALUE
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET AL32UTF8
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 11.2.0.1.0
It is working fine if I reduce from 4000 to 3500 . But I want to use 4000.
Please let me know if any solutionyou are using a multibyte character set:
NLS_CHARACTERSET AL32UTF8
so each character takes between 1 and 4 bytes of storage.
a varchar2(4000) column can only hold 4000 BYTES. Regardless of the character set - varchar2 is limited to 4000 bytes.
In a single byte character set, that is 4000 characters as a character = a byte
In your character set, a varchar2(4000) can hold somewhere between 1000 and 4000 characters - depending on what the characters are.
So, you must have some CLOB whose first 4000 characters include at least one "more than one byte" character. That won't fit into a varchar2(4000)
Your approach of backing off the substr size is reasonable (and you'll need to remember that in your application - end users can type in as little as 1000 characters and get an error about the column being too small!) as it reduces the number of BYTES to be belong 4000. -
Receiver determination using substring in filename in file adapter
Hi
In PI 7.11 I would like to determine the receiver based on a substring in the filename in a file receiver adapter. I am planning on using a context object but am having trouble entering the correct code in the "Right Operand" field.
I have tried selecting Context Object = Filename http://sap.com/xi/XI/System/File and entering this code in the Right Operand: "contains(substring('_4000_'))" and an "=" in the as I am looking for a filename, that contains the substring "_4000_".
I would like to avoid using an extra map and using Dynamic Configuration, as I thing this would be the most elegant way of fixing it
Is there a way of referencing the context object if I chose xpath in stead of context object?
MIkaelHi Mikael,
I have the same scenario like you , could you please tell me about the condition how to you use XPath for Context Object
I need to check the file name and according to that I have to put the file in the different directory.
Source File: XXXX_IN_xxxx
XXXX_PH_xxxx
I have to check the 7th and 8th Char of the file and according to that I have to place the file in the folder
Target: DGE008\IN\Inbound
DGE008PH\Inbound
I don't know how to used the XPATH for file and specially how to use the substring in that.
Could you please help.
Thanks, -
Get substring of file name up to the last underscore
I have filenames and I want to get a substring of the file name up to the last underscore if it exists and if not up to the last period.
Create table FileNames (fileName varchar(40))
insert into FileNames values ('this_is_a_long_filename.ext')
insert into FileNames values ('this_is_an_even_longer_filename.ext')
insert into FileNames values ('short_filename.ext')
insert into FileNames values ('supershort.ext')
What I want returned is:
this_is_a_long
this_is_an_even_longer
short
supershort
Any help would be appreciated.
lgThis will work too...
IF OBJECT_ID('tempdb..#FileNames') IS NOT NULL
DROP TABLE #FileNames
GO
CREATE TABLE #FileNames (
fileName varchar(40)
insert into #FileNames values ('this_is_a_long_filename.ext')
insert into #FileNames values ('this_is_an_even_longer_filename.ext')
insert into #FileNames values ('short_filename.ext')
insert into #FileNames values ('supershort.ext')
SELECT
fn.fileName,
LEFT(fn.fileName, LEN(fn.fileName) - COALESCE(NULLIF(PATINDEX('%[_]%', REVERSE(fn.fileName)), 0), PATINDEX('%.%', REVERSE(fn.fileName))))
FROM
#FileNames fn
Jason Long
Maybe you are looking for
-
How to display errror message in a form based on a procedure
I created a single-level form based on a procedure. In this form, I would like to generate an error message inside of a custom button, so I used the following inside of that button: p_session.set_value (p_block_name => 'DEFAULT', p_attribute_name =>
-
Exception occurred: "AI Group Config"
Recently I have gotten a problem with my LabVIEW VI, used to acquire data from a MEA-Chip. As soon as I try to change the setup of my PCI 6071 E I get he following error: Exception occurred within the external code called by a call library function N
-
Hi all, How do I select G/L account of Revenue a/c by SQL query?Is it possible to load Revenue a/c into a matrix using DBDatasource with condition(oCondition)? Please help, thanks in advance, BBN
-
Just a post to say, I upgraded to OS X 4.5 without a hitch. This post is for anyone else who is still hesitating. Thanks to participating members of this forum. Power Mac G4 Gigabite Ethernet 1GHz 1Gig Ram Mac OS X (10.4.5)
-
Portege R500 screen rotation on Vista
Hello, I've a Portege R500. I've installed WinXP on it as soon as it arrived so didn't have any experience with Vista. I used iRotate software to rotate my screen desktop on the external display. Later on, I installed Windows Vista Enterprise but scr