fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: HELP required ;-)

HELP required ;-) 1 year 5 months ago #1

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
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 :-



and here is the string data I was using at the time of my failure ;-0((



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.
Attachments:

Please Log in or Create an account to join the conversation.

HELP required ;-) 1 year 5 months ago #2

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1436
  • Karma: 6
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
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

HELP required ;-) 1 year 5 months ago #3

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1436
  • Karma: 6
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:
"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
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

HELP required ;-) 1 year 5 months ago #4

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
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

HELP required ;-) 1 year 5 months ago #5

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
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.

Please Log in or Create an account to join the conversation.

HELP required ;-) 1 year 5 months ago #6

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
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 :-



Now the code which parses the full original CSV line (record) to make that shown above :-



And now a couple of smaller images to show that we now have 20 separate strings in the array :-





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 :-





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.

Please Log in or Create an account to join the conversation.

HELP required ;-) 1 year 5 months ago #7

Phil,

The official syntax to create a char array is:
LOCAL charArray AS Char[]
charArray := <Char> {'a', 'b', 'c'}

So general for any typed array
<TypeName> { valuelist }

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

HELP required ;-) 1 year 5 months ago #8

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1436
  • Karma: 6
Hi Phil,

you could use also this syntax to split a string
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
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

HELP required ;-) 1 year 5 months ago #9

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.

Please Log in or Create an account to join the conversation.

HELP required ;-) 1 year 5 months ago #10

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Hi guys,

This is all that was required once Robert had provided the correct syntax :-



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.
Attachments:

Please Log in or Create an account to join the conversation.

HELP required ;-) 1 year 5 months ago #11

Hi Karl,

Karl Faller wrote: hey, there's even a "code" style here to automatically do a nice formatting ;)


What? How?

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

HELP required ;-) 1 year 5 months ago #12

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1436
  • Karma: 6
Hi Chris,

"nice" is a bit too much.

If you format with this one



you will get that format
class Chris inherit XSProgrammer

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it
Attachments:

Please Log in or Create an account to join the conversation.

HELP required ;-) 1 year 5 months ago #13

Hi Wolfgang,

Ah, ok, thanks! It would had been embarrassing if there was a style for indenting etc and I wasn't aware of it :)

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

  • Page:
  • 1