cancel
Showing results for 
Search instead for 
Did you mean: 

Split a String into two Separate String

SOLVED
RoniWonders
Member
Solved!

Split a String into two Separate String

Hi so I'm trying to split a string into two halves then put them back together with the second character separating them. For example, if the string is "apple", I want to it to be divided as "app" and "le" then put the back together with "p" in the middle to make "lepapp". I've been trying to use the Search/Split String but I'm not able to get the second half of the string. 

 

I've figure it out with an even number of characters string like "home" to make "meoho" but it's the odd strings that make it confusing to me.

12 REPLIES 12
raphschru
Active Participant

Re: Split a String into two Separate String

Hi Roni,

 

You are on the right track using "Search/Split String".

The second half of your string would be the "match + rest of string" output. Also, for odd numbers, since you want to split after the middle character, you could divide the size of the original string by 2 and round up with "Round Toward + Infinity" to compute the split offset.

 

Regards,

Raphaël.

mcduff
Trusted Enthusiast
Solution

Re: Split a String into two Separate String

Message contains an image

snip.png

 

See if you can use String Functions; this one uses array functions.

 

mcduff_0-1688686713339.pngmcduff_1-1688686730584.png

 

UliB
Active Participant
Solution

Re: Split a String into two Separate String

Message contains an image

Here is a string version.

 

Split String.png

 

JÞB
Knight of NI

Re: Split a String into two Separate String

Message contains an image

@mcduff wrote:

snip.png

 

See if you can use String Functions; this one uses array functions.

 

mcduff_0-1688686713339.pngmcduff_1-1688686730584.png

 


Nicely done! But, the decrement is not necessary delete from array defaults to last value!  Also, the To I32 is ( in this case) better handled as an implied coercion.  Those coercion dots are not always evil!  I actually like the Quotient + Remainder Mod 2 demonstrated by Ulib.


"Should be" isn't "Is" -Jay
mcduff
Trusted Enthusiast

Re: Split a String into two Separate String


@JÞB wrote:
Those coercion dots are not always evil!  I actually like the Quotient + Remainder Mod 2 demonstrated by Ulib.

I like Ulib Remainder Mod too. Agree about coercion dots, but the OP appeared to be relatively new to LabVEIW so tried to show best practices, which may not be necessary true or needed for all cases.

 


@JÞB wrote:

But, the decrement is not necessary delete from array defaults to last value!  


I am allergic to Delete from Array. In this case it does not matter, but it always gives buffer allocations which I don't like.

mcduff
Trusted Enthusiast

Re: Split a String into two Separate String

Message contains an image

One more String solution using @UliB quotient remainder

 

snip.png

RoniWonders
Member

Converting ASCII code to Hexdecimal String

Message contains an attachment

So I have set up the program to convert the code to hexadecimal however it isn't fully putting out the hexadecimal.

For example, I want convert "skede" to hexadecimal which would be "736B656465" however it only displays "736B6564". Its missing the last letter which would be "65". What am I doing wrong?

Highlighted
GerdW
Knight of NI

Re: Converting ASCII code to Hexdecimal String

Message contains an image Message contains an attachment

Hi Roni,

 


@RoniWonders wrote:

What am I doing wrong?


  • You don't care about coercion dots.
  • You use a rounding function.
  • You do your stuff way to complicated…
  • You don't provide code. Keep in mind: we cannot debug/edit/run images in LabVIEW!

It could as easy as this:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
altenbach
Knight of NI

Re: Converting ASCII code to Hexdecimal String

Message contains an image

Please attach your Vi instead of pictures.

I don't think you need anything orange.

 

Your code is incredibly convoluted, why not so something simple as follows:

 

altenbach_0-1688756082173.png