HELP required ;-)

This forum is meant for questions and discussions about the X# language and tools
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP required ;-)

Post by Phil Hepburn »

Hi Robert, Chris, and guys,

I have done too much today with my new app of the Address Book for Cologne 2018. My brain is dead and my memory dulled.

All I wish to do is split a string into parts with the delimiter being in my case a '$' character. I have made a suitable string with 19 such delimiters.

The C# code I am trying to re-work and code in X# is very similar to the details included.

Can any one get the code to work in X# and do a trial test as well ?

here is the code :-
HelpForum01.jpg
HelpForum01.jpg (27.29 KiB) Viewed 681 times
and here is the string data I was using at the time of my failure ;-0((
HelpForum02.jpg
HelpForum02.jpg (80.68 KiB) Viewed 681 times
I am aware that I still have a leading and trailing single double quote - these need to be removed.

HELP- please,

Thanks for listening.

Regards,
Phil.
Wales, UK.
User avatar
wriedmann
Posts: 3765
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

HELP required ;-)

Post by wriedmann »

Hi Phil,

IMHO posting images is not very helpful..... So everyone that likes to try your code has to type not only your code, but also your test data.
If you had posted your data as code everyone could only copy and paste.

I don't see any problems in your code, but to check it in a small sample I have to retype it.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3765
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

HELP required ;-)

Post by wriedmann »

Hi Phil,

I have some problems to understand what your problem really is. Your sample string is using "$" as delimiter, but your code is assuming "," as delimiter.

The C# code seems to work, I see no problem or error in it.

Your code first of all is not using any String:Split() method, and as second you are replacing the sequence "," with "$".

IMHO your code should be able to deal with such constructs:

Code: Select all

"this is a string with a $ sign"$12345$this is a normal string$and this is nothing of special


Therefore you don't need to remove the "," (or better the "$") sequences, otherwise it would fail if a $ sign is found in any substring.

Personally I see two possibilities:
- use the VO way and write your own parser - I can give you working code if you wish
- use the .NET way, maybe with this sample here:
https://coding.abel.nu/2012/06/built-in-net-csv-parser/

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4540
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

HELP required ;-)

Post by robert »

Phil,

In addition to what Wolfgang said:
if the problem in your code is caused by an unbalanced quote, parenthesis or something like that, then it is very likely that we will not see the problem because we accidentally do not make the same mistake.

And when reading your message I have no idea what the problem is.
Are you asking for the correct syntax for the char array ?
I personally always forget that too, so I sometimes use the ToCharArray() method to get that kind of array

nuLine:Split("$":ToCharArray())

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP required ;-)

Post by Phil Hepburn »

Yes Robert,

It seemed to be the creation of a correct character array which is giving me grief.

I will try again soon, with a fresh mind and clear brain.

If all else fails I will write a recursive method in the normal string handling way/approach.

Sorry if I upset some guys with images - that's just the way things are!

Fingers crossed,
Phil.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP required ;-)

Post by Phil Hepburn »

Hi again Robert,

Your suggested code for declaring a character array sorted me and my problem out in less than a minute - THANKS!

For those who like them, I have posted the images to show some tidied X# code which works - yes, okay, there is still some test code present, but then I am still at the development and test stage.

I took Wolfgang's comment on board about my choice of 'replaced' delimiter and its possible existence in my address book data fields. I have now changed in from '$' to '%' and I will write some 'Converter' code to trap and eliminate any entries of '%' from my data field displays. My address fields will not be allowed to have '%' included in the string input data.

The reason I chose to do a 'Replace' was because it greatly simplified the necessary string and character handling shown in sample posted on CodeProject, StackOverflow and C# Corner and the likes.

Robert, do you know of any other syntax for creating a Character array when we wish to specify a character or two at define time? I too get confused, both with Character and String arrays.

Phil.

Now here are a few images of working 'stuff' :-

The full CSV record read from a file and translated / converted :-
AB_working_01.jpg
AB_working_01.jpg (35.96 KiB) Viewed 681 times
Now the code which parses the full original CSV line (record) to make that shown above :-
AB_working_02.jpg
AB_working_02.jpg (168.35 KiB) Viewed 681 times
And now a couple of smaller images to show that we now have 20 separate strings in the array :-
AB_working_03.jpg
AB_working_03.jpg (51.71 KiB) Viewed 681 times
AB_working_04.jpg
AB_working_04.jpg (51.53 KiB) Viewed 681 times
You may be interested to see that I also made stuff easier with the string handling by defining escaped small sequences, so they could be added without cause for more double quotes and assembly of the line time :-
AB_working_05.jpg
AB_working_05.jpg (59.19 KiB) Viewed 681 times
AB_working_06.jpg
AB_working_06.jpg (61.27 KiB) Viewed 681 times
You may have noticed that all my 20 Address Book data fields are encoded to be contained within a pair of double quotes. This just makes things easier when decoding, if it is done as shown above.

I did my homework on Wikipedia and other places, and CSV is not a perfect science, by any stretch of the imagination. I think that my test will be if my encoded files load OK into Excel, and show properly all 20 fields even with some more extreme string data encoded entered.

Hope some of this interests a few of you guys.
Phil.
User avatar
robert
Posts: 4540
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

HELP required ;-)

Post by robert »

Phil,

The official syntax to create a char array is:

Code: Select all

LOCAL charArray AS Char[]
charArray := <Char> {'a', 'b', 'c'}
So general for any typed array

Code: Select all

<TypeName> { valuelist }
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3765
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

HELP required ;-)

Post by wriedmann »

Hi Phil,

you could use also this syntax to split a string

Code: Select all

aReturn := cString:Split( <char>{ 'r', 'n' }, StringSplitOptions.RemoveEmptyEntries )
It looks a bit ugly, I know. But the array needs to be typed as <char>.

Wolfgang

P.S. I'm not upset with your posting of images - it makes it only a lot harder to build a sample. Therefore I use images only when absolutely needed, and write the code directly as text - it is not so beautyful, but better to work with. And whenever needed, I add my test data and/or test application to the message.
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1584
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

HELP required ;-)

Post by FFF »

Phil Hepburn wrote:Sorry if I upset some guys with images - that's just the way things are!
Why? Take a snapshot of things which aren't "copiable", but for code mark, copy, paste - hey, there's even a "code" style here to automatically do a nice formatting ;)

K.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP required ;-)

Post by Phil Hepburn »

Hi guys,

This is all that was required once Robert had provided the correct syntax :-
XSforum_13.jpg
XSforum_13.jpg (52.72 KiB) Viewed 681 times
Not a lot of typing in my book ;-0)

I shudder to think how much typing I have made in posting my contributions to Pearls and 'ClickStart' over the years B)

So who's counting ?

Have a nice day,
Phil.
Post Reply