SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-20-2010, 09:46 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Easier way to insert character into String

Lets say I have a string consisting of numbers and letters that is 32 characters long. I want to insert a "-" every 2 spaces is there a quick and easy way to do this without looping?
Reply With Quote
  #2  
Old 01-20-2010, 11:01 AM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
Not really. And any other function that you DID use would in turn do the looping in it, so it's not really a performance concern.

Well, I guess that's not entirely correct, if you KNOW the string is always 32 characters long, you could string together a long list of substrings:

Substring(input,0,2) & "-" & Substring(input,2,2) & "-" & Substring(input,4,2)... etc...
__________________
Buy Fuzzy a beer! (Fuzzy likes beer)

unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers.
Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA.
Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S
Other Clients: Mi Box in Master Bedroom, HD-200 in kids room
Reply With Quote
  #3  
Old 01-20-2010, 12:16 PM
jreichen's Avatar
jreichen jreichen is offline
Sage Icon
 
Join Date: Jul 2004
Posts: 1,192
Regular expressions make this pretty easy as long as you can find the right one I kept getting an extra dash at the end until I found the answer (the funny-looking '(?!$)' ) on this page.
Code:
"ABCDEFGH".replaceAll("(.{2})(?!$)", "$1-")
__________________
Server: Intel Core i5 760 Quad, Gigabyte GA-H57M-USB3, 4GB RAM, Gigabyte GeForce 210, 120GB SSD (OS), 1TB SATA, HD HomeRun.
Extender: STP-HD300, Harmony 550 Remote,
Netgear MCA1001 Ethernet over Coax.
SageTV: SageTV Server 7.1.8 on Ubuntu Linux 11.04, SageTV Placeshifter for Mac 6.6.2, SageTV Client 7.0.15 for Windows, Linux Placeshifter 7.1.8 on Server and Client
, Java 1.6.
Plugins: Jetty, Nielm's Web Server, Mobile Web Interface.

Reply With Quote
  #4  
Old 01-20-2010, 12:32 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by jreichen View Post
Regular expressions make this pretty easy as long as you can find the right one I kept getting an extra dash at the end until I found the answer (the funny-looking '(?!$)' ) on this page.
Code:
"ABCDEFGH".replaceAll("(.{2})(?!$)", "$1-")
You hit another homerun thanks for the link and info works like a charm.
Reply With Quote
  #5  
Old 01-20-2010, 09:08 PM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
They are powerful.. but damn i hate RegEx... ;-)
__________________
Buy Fuzzy a beer! (Fuzzy likes beer)

unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers.
Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA.
Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S
Other Clients: Mi Box in Master Bedroom, HD-200 in kids room
Reply With Quote
  #6  
Old 01-20-2010, 09:33 PM
jreichen's Avatar
jreichen jreichen is offline
Sage Icon
 
Join Date: Jul 2004
Posts: 1,192
Yeah my original regex kept appending a dash at the end. It took me a while to find the magic '(?!$)' that prevented it. It's one of those "special constructs" in the Javadoc that I never understood until now.
__________________
Server: Intel Core i5 760 Quad, Gigabyte GA-H57M-USB3, 4GB RAM, Gigabyte GeForce 210, 120GB SSD (OS), 1TB SATA, HD HomeRun.
Extender: STP-HD300, Harmony 550 Remote,
Netgear MCA1001 Ethernet over Coax.
SageTV: SageTV Server 7.1.8 on Ubuntu Linux 11.04, SageTV Placeshifter for Mac 6.6.2, SageTV Client 7.0.15 for Windows, Linux Placeshifter 7.1.8 on Server and Client
, Java 1.6.
Plugins: Jetty, Nielm's Web Server, Mobile Web Interface.

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Non-english filename character support? beatmania SageTV HD Theater - Media Player 1 06-08-2009 06:16 PM
Central European Character problems alanwww1 SageTV Software 0 12-15-2007 12:20 PM
Unicode character support with MVP Lucas SageTV Media Extender 0 01-10-2006 01:52 AM
Interfacing with character LCDs brandium General Discussion 2 01-17-2005 10:18 PM
support of non-english character in Music Jukebox sarudoshi2004 SageTV Software 3 10-14-2004 07:38 AM


All times are GMT -6. The time now is 05:48 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.