Replace a string by another

ombacke
Member Posts: 44
I want to change every occurance of & to and
The CONVERTSTR function does not let me do that since & and and have different number of characters..
Does anyone know of a way of doing this??
The CONVERTSTR function does not let me do that since & and and have different number of characters..
Does anyone know of a way of doing this??
0
Comments
-
I would probably write a concatenation function. You get the position of the &, and then you cut whatever is in front of it, do "+ 'and' +" and then whatever is after it.0
-
Here, you can use this function as is.
It's from the archives...:
ReplaceString(String : Text[250];FindWhat : Text[250];ReplaceWith : Text[250]) NewString : Text[250] WHILE STRPOS(String,FindWhat) > 0 DO String := DELSTR(String,STRPOS(String,FindWhat)) + ReplaceWith + COPYSTR(String,STRPOS(String,FindWhat) + STRLEN(FindWhat)); NewString := String;
[edit]
Oh, and then you just use the function as:ReplaceString('String which contains &','&','AND');
The return will be:'String which contains AND'
Nelson Alberto0 -
Heh
Some day or later, everbody needs to write a decent string manipulation codeunit in navision - reverse, replace, ltrim, rtrim, alltrim...
It's all about for cycles and char variables.
Do It Yourself is they key. Standard code might work - your code surely works.0 -
-
I have quite a few codeunits which can be imported to any database as they don't depend on any other object.
Stuff like String Handling, Array Handling, Excel, Word and Outlook Automation, File Manipulation, Date and Time utilities, etc.
Well, maybe you can't just import a few of them.
Mostly the Microsoft Office stuff depends on Office being installed, of course. :roll:Nelson Alberto0 -
hi everybody!
I'm a navision newbie so please don't shoot me!!! :P
I searched for those "archives" in all mibuso.com, but I didn't find them, could you please give me a link or something similar?
thanks a lot!
P0 -
I actually meant my archives... it's stuff I collected over the years and which I have lying around in databases and FOB's.
So, no link which I can give you. sorry.Nelson Alberto0 -
ah ok, I supposed it was like this...
so, I disturb you a little bit again...could you post some string manipulation function or mail me a little fob with these functions?
I'm looking for some "stupid" but very useful functions like trim, reverse and similar, but I haven't idea of how to create them...
thanks for answering!
P.0 -
Well, string manipulation functions are really not that hard.
When you are in the C/AL editor, use the Symbol Menu (F5) to see all the existing string functions.
You will find them in SYSTEM, String. With these you should be able to tackle most string-related problems.
For example, in order to trim a string you can use the DELCHR function:
DELCHR(String,'<>') will delete spaces at the beginning and end of the string.Nelson Alberto0 -
Hi there!
If you want to replace a substring with new subtring which contains the same charachters, the ReplaceString function by nelson will cycling over the loop. So you can use the following function:LOCAL ReplaceString(String : Text;FindWhat : Text;ReplaceWith : Text) NewString : Text FindPos := STRPOS(String,FindWhat); WHILE FindPos > 0 DO BEGIN NewString += DELSTR(String,FindPos) + ReplaceWith; String := COPYSTR(String,FindPos + STRLEN(FindWhat)); FindPos := STRPOS(String,FindWhat); END; NewString += String;
For example, if you want escape characters in XML you can use:ReplaceString(XMLBody,'"','\"');
Input:
<FullName>Публичное акционерное общество "Рога и Копыта"</FullName>
Output:
<FullName>Публичное акционерное общество \"Рога и Копыта\"</FullName>1 -
@Kirill do you really think that the guy hasn't figured it out during those 12.5 years?Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-033 -
I think more people than that guy are reading this thread
, so it kinda still useful.
1 -
Is that solved what you are trying to achieve?
If yes then please verify!!Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
Last active 2006-12-05.. I'd check Canadian gravestones1
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions